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

Aws Lambdas - undefined method `[]' for nil:NilClass #99

Closed
cgaube opened this issue Jul 17, 2024 · 3 comments
Closed

Aws Lambdas - undefined method `[]' for nil:NilClass #99

cgaube opened this issue Jul 17, 2024 · 3 comments

Comments

@cgaube
Copy link

cgaube commented Jul 17, 2024

Getting some errors with the logger gem when executing

logger = Logger.new($stdout)
logger.info 'test'
  "errorMessage": "undefined method `[]' for nil:NilClass",
  "errorType": "Function<NoMethodError>",
  "stackTrace": [
    "/var/task/vendor/bundle/ruby/3.2.0/gems/logger-1.6.0/lib/logger.rb:384:in `level'",
    "/var/task/vendor/bundle/ruby/3.2.0/gems/logger-1.6.0/lib/logger.rb:653:in `add'",
    "/var/task/vendor/bundle/ruby/3.2.0/gems/logger-1.6.0/lib/logger.rb:697:in `info'",

error does not appear when using version 1.5.3 of the gem

v1.5.3...v1.6.0

For some reason it looks like the initialize function is not being triggered and thus @level_override is never set to {}

@cgaube
Copy link
Author

cgaube commented Jul 17, 2024

Wow so here is the culprit
AWS lambda ecosystem is actually monkey patching the logger class
and because my code is using $stdout it goes though their patch. that does NOT setup

  def initialize(logdev, shift_age = 0, shift_size = 1048576, level: Logger::DEBUG,
                   progname: nil, formatter: nil, datetime_format: nil,
                   binmode: false, shift_period_suffix: '%Y%m%d')
    #  use unpatched constructor if logdev is a filename or an IO Object other than $stdout or $stderr
    if logdev && logdev != $stdout && logdev != $stderr
      super(logdev, shift_age, shift_size, level: level, progname: progname,
                      formatter: formatter, datetime_format: datetime_format,
                      binmode: binmode, shift_period_suffix: shift_period_suffix)
    else
      self.level = level
      self.progname = progname
      @default_formatter = LambdaLogFormatter.new
      self.datetime_format = datetime_format
       self.formatter = formatter
      @logdev = TELEMETRY_LOG_SINK
    end
  end
end

I am not sure where this code is defined or what Github project to use to open an issue

@cgaube
Copy link
Author

cgaube commented Jul 17, 2024

somebody beat me to it
aws/aws-lambda-ruby-runtime-interface-client#33

@hsbt
Copy link
Member

hsbt commented Sep 10, 2024

This report has been resolved by https://github.com/ruby/logger/releases/tag/v1.6.1

@hsbt hsbt closed this as completed Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants