Skip to content

Commit

Permalink
Merge pull request #102 from maglevhq/101-less-verbose-error-messages…
Browse files Browse the repository at this point in the history
…-if-exception-when-rendering-a-section

feat: make the logs less verbose if something wrong happens
  • Loading branch information
did authored Dec 16, 2024
2 parents c8e2cdf + c62aadc commit 46b35d6
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/components/maglev/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Maglev
class BaseComponent
include ::Maglev::Inspector

extend Forwardable
def_delegators :view_context, :render

Expand Down Expand Up @@ -50,5 +52,9 @@ def find_setting(settings, setting_id)
rescue NoMethodError
raise "[Maglev] We're sorry but there is no '#{setting_id}' setting in your section/block."
end

def site_id
site.id
end
end
end
10 changes: 10 additions & 0 deletions app/components/maglev/block_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,15 @@ def dom_data
def tag_data
{ maglev_block_id: id }
end

private

def section_id
section.id
end

def inspect_fields
%w[id site_id section_id name type].map { |field| [field, send(field)] }
end
end
end
8 changes: 8 additions & 0 deletions app/components/maglev/content/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Maglev
module Content
class Base
include ::Maglev::Inspector

extend Forwardable
def_delegators :scope, :site, :config

Expand Down Expand Up @@ -47,6 +49,12 @@ def asset_host
instance_exec(site, &config.asset_host)
end
end

private

def inspect_fields
%w[scope tag_id].map { |field| [field, send(field).inspect] }
end
end
end
end
18 changes: 18 additions & 0 deletions app/components/maglev/inspector.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Maglev
module Inspector
def inspect
string = "#<#{self.class.name}:#{object_id} "
string << inspect_fields
.map { |(name, value)| "#{name}: #{value}" }
.join(', ') << '>'
end

private

def inspect_fields
[]
end
end
end
4 changes: 4 additions & 0 deletions app/components/maglev/page_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ def build_section(definition, attributes)
rendering_mode: rendering_mode
)
end

def inspect_fields
[['site_id', site.id], ['page_id', page.id], ['theme', theme.id]]
end
end
end
4 changes: 4 additions & 0 deletions app/components/maglev/section_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,9 @@ def render_error
</div>
HTML
end

def inspect_fields
%w[id site_id type].map { |field| [field, send(field)] }
end
end
end
2 changes: 1 addition & 1 deletion spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test

config.active_storage.variant_processor = :mini_magick

# Tell Action Mailer not to deliver emails to the real world.
Expand Down

0 comments on commit 46b35d6

Please sign in to comment.