question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ruby handler param bugs

See original GitHub issue

Describe the issue There are several weird bugs happening in sandbox for Ruby lambdas:

  1. When setting the handler method arguments as
def handler(event, context)
  .....
end

You get the following error: handler': wrong number of arguments (given 0, expected 2) (ArgumentError)

  1. To fix the above error, you can provide a default empty hash to the arguments:
def handler(event={}, context={})
  .....
end

However, this causes different issues when introducing an error into the code. If I were to then intentionally cause a bug, the function is now executed twice in a row, and the value of the arguments are empty the second time around.

def handler(event = {}, context = {})
 puts event
 puts context
 puts foo # raise an undefined local variable error
 { body: 'hello world' }
end

Result:

/Users/jeremycohenhoffing/projects/lambda-test-app/src/http/get-index/index.rb:9:in `handler': undefined local variable or method `foo' for main:Object (NameError)
   from -e:16:in `rescue in <main>'
   from -e:12:in `<main>'
{:event=>{"version"=>"2.0", "routeKey"=>"GET /", "rawPath"=>"/", "rawQueryString"=>"", "cookies"=>["some_cookies"], "headers"=>{"host"=>"localhost:3333", "cache-control"=>"max-age=0", "sec-ch-ua"=>"\", "accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept-language"=>"en-US,en;q=0.9", "sec-gpc"=>"1"}, "requestContext"=>{"http"=>{"method"=>"GET", "path"=>"/"}, "routeKey"=>"GET /"}, "isBase64Encoded"=>false}, :context=>{"aws_request_id"=>"xxxxxx", "function_name"=>"sandbox-get-index", "function_version"=>"$LATEST", "invoked_function_arn"=>"sandbox", "memory_limit_in_mb"=>1152}}
{} 
{} # second time the function is executed with arguments now empty
{}

Please also see this discussion: https://discord.com/channels/880272256100601927/884128391341678742/953697307528929280

Steps to reproduce Steps to reproduce the behavior:

  1. I created a boilerplate Architect v10.1.0 project here: https://github.com/jcohenho/ruby-lambda-test-arc-app
  2. Run the app with npx arc sandbox
  3. For the first issue, change the handler arguments to
def handler(event, context)
  1. For the second issue, intentionally add a bug and see that the handler is executed twice

Expected behavior

  1. I expect the lambda handler to run only once
  2. I expect the lambda to not have weird params issues and show correct errors

Screenshots If applicable, add screenshots to help explain your problem

Desktop Please complete the following information (if appropriate):

  • OS: MacOS Catalina 10.15.6
  • Browser: Chrome
  • Version: 98.0.4758.109

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
brianlerouxcommented, Apr 6, 2022

lots of stuff on the go but I’ll do my best to have a look today 🙏

1reaction
jcohenhocommented, Mar 25, 2022

@brianleroux @ryanblock I would love to help contribute to this but I need a little help and guidance for how to run and test this sandbox code locally. I’m not sure where to begin so any advice would be much appreciated 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Need a handler. Pass the with: keyword argument or provide a ...
Recently I update my app from Ruby version 2.6 ...
Read more >
How to Troubleshoot Ruby Applications - Stackify
You may see that there's already a bug in there. We'll look at different ways to isolate it. Here is the API: Troubleshooting...
Read more >
Log Error Handler: revealing and processing bugs gem
Here you can find information about the Log Error Handler, powerful tool, that can help you to reveal and process bugs on your...
Read more >
Ruby Exception Handling - Primer for Dealing with Errors in ...
Let's go through some basic Ruby error handling, and discover how easy it ... Exception handlers are blocks of code that are called...
Read more >
Feature #5446: at_fork callback API - Ruby master
It would be good if Ruby provides an API for registering fork() handlers. ... Related to Ruby master - Bug #14009: macOS High...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found