Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't capture NameError if its not a missing component #5432

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions admin/lib/solidus_admin/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,22 @@ def menu_items

def components
@components ||= Hash.new do |_h, k|
"solidus_admin/#{k}/component".classify.constantize
rescue NameError
prefix = "#{ENGINE_ROOT}/app/components/solidus_admin/"
suffix = "/component.rb"
dictionary = Dir["#{prefix}**#{suffix}"].map { _1.delete_prefix(prefix).delete_suffix(suffix) }
corrections = DidYouMean::SpellChecker.new(dictionary: dictionary).correct(k.to_s)

raise ComponentNotFoundError, "Unknown component #{k}#{DidYouMean.formatter.message_for(corrections)}"
const_name = "solidus_admin/#{k}/component".classify

unless Object.const_defined?(const_name)
prefix = "#{ENGINE_ROOT}/app/components/solidus_admin/"
suffix = "/component.rb"
dictionary = Dir["#{prefix}**#{suffix}"].map { _1.delete_prefix(prefix).delete_suffix(suffix) }
corrections = DidYouMean::SpellChecker.new(dictionary: dictionary).correct(k.to_s)

raise ComponentNotFoundError.new(
"Unknown component #{k}#{DidYouMean.formatter.message_for(corrections)}",
k.classify,
receiver: ::SolidusAdmin
)
end

const_name.constantize
end
end

Expand Down