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

Exception: NoMethodError: undefined method `[]' for nil #285

Closed
srajan-dadhich opened this issue Jun 25, 2024 · 1 comment · Fixed by #286
Closed

Exception: NoMethodError: undefined method `[]' for nil #285

srajan-dadhich opened this issue Jun 25, 2024 · 1 comment · Fixed by #286

Comments

@srajan-dadhich
Copy link

Environment

Provide at least:

  • Ruby Version.
    ruby 3.3.1
  • Rails Version.
    Rails 7.0.4.3
  • Semantic Logger Version.
    semantic_logger-4.15.0
  • Rails Semantic Logger Version.
    rails_semantic_logger 4.14.0
  • Other Application/framework names and versions (e.g. Puma, etc.).
  • Rails configuration. Only need the settings related to Rails Semantic Logger and Semantic Logger.
    `semantic_appender_options = {
    level: Rails.application.config.log_level,
    formatter: Rails.application.config.rails_semantic_logger.format,
    }

case Rails.application.config.log_destination
when :stdout
SemanticLogger.add_appender(io: STDOUT, **semantic_appender_options)
when :file
path = Rails.root.join("log", "rails_logger_#{Rails.env}.json").to_s
SemanticLogger.add_appender(file_name: path, **semantic_appender_options)
else
raise NotImplementedError("Invalid log_destination #{Rails.application.config.log_destination}")
end

Rails.logger.level = Rails.application.config.log_level`

  • Full Stack Trace, if an exception is being raised.
    2024-06-25 19:06:00.035405 E [47683:SemanticLogger::Appenders diagnostic_context.rb:323] SemanticLogger::Appenders -- Failed to log to appender: SemanticLogger::Appender::File -- Exception: NoMethodError: undefined method []' for nil
    /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/log.rb:252:in extract_file_and_line' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/log.rb:259:in file_name_and_line'
    /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/formatters/raw.rb:52:in file_name_and_line' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/formatters/raw.rb:127:in call'
    /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/formatters/json.rb:12:in call' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/file.rb:188:in log'
    /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appenders.rb:31:in block in log' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appenders.rb:30:in each'
    /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appenders.rb:30:in log' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/async.rb:152:in process_messages'
    /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/async.rb:121:in process' /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/semantic_logger-4.15.0/lib/semantic_logger/appender/async.rb:77:in block in thread'
    /Users/srajan/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in block in create_with_logging_context'

Note:

  • If the issue is with extensions to Rails to make it use Semantic Logger, please report the issue at Rails Semantic Logger.
  • All appender issues should be reported here.

Expected Behavior

  • Describe your expectation of how Semantic Logger should behave, perhaps by showing how the builtin Ruby logger behaves.
    extract_file_and_line here should handle case of an empty stacktrace,
  • Provide a standalone Ruby script or a link to an example repository that helps reproduce the issue.
    It originated from the code that is getting called by logging gem which is an external dependency in another library as can be seen in stacktrace.

Actual Behavior

  • Describe or show the actual behavior.
    It shouldn't fail when there is no match in the last entry of stacktrace.
Screenshot 2024-06-26 at 1 18 39 AM
reidmorrison added a commit that referenced this issue Jun 29, 2024
Handle a stack trace that does not return a known file and line number #285
@reidmorrison
Copy link
Owner

Thank you for reporting the full stack trace, made it simple to isolate and add handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants