Skip to content

Commit 0f0886b

Browse files
committed
avoid crashing in no assets (api only) mode
Rails apps can run in API only mode, which means they do not have an asset pipeline. If one tries to call config.assets for an app like that one gets the following crash: ``` NoMethodError: undefined method 'assets' for an instance of Rails::Application::Configuration (NoMethodError) Did you mean? asset_host my-app/config/environment.rb:7:in '<main>' /bundle:25:in 'Kernel#load' bundle:25:in '<main>' ``` The code a few lines above (95-100) ([ref](https://github.com/0robustus1/rails_semantic_logger/blob/master/lib/rails_semantic_logger/engine.rb#L95-L100)) is already written defensively. This does the same for this invocation of config.assets.
1 parent c60ff0d commit 0f0886b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/rails_semantic_logger/engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class Engine < ::Rails::Engine
204204
RailsSemanticLogger::Rack::Logger.started_request_log_level = :info if config.rails_semantic_logger.started
205205

206206
# Silence asset logging by applying a filter to the Rails logger itself, not any of the appenders.
207-
if config.rails_semantic_logger.quiet_assets && config.assets.prefix
207+
if config.rails_semantic_logger.quiet_assets && config.respond_to?(:assets) && config.assets.prefix
208208
assets_root = config.relative_url_root.to_s + config.assets.prefix
209209
assets_regex = %r(\A/{0,2}#{assets_root})
210210
RailsSemanticLogger::Rack::Logger.logger.filter = ->(log) { log.payload[:path] !~ assets_regex if log.payload }

0 commit comments

Comments
 (0)