Method: Jets::PolyFun::BaseExecutor#run_lambda_executor
- Defined in:
- lib/jets/poly_fun/base_executor.rb
#run_lambda_executor(event, context) ⇒ Object
When polymorphic method errors, this method reproduces an error in the lambda format Here’s some examples to help example:
Example of what the raw python prints out to stderr:
Traceback (most recent call last):
File "/tmp/jets/lite/executor/20180804-10727-mcs6qk/lambda_executor.py", line 6, in <module>
resp = handle(event, context)
File "/tmp/jets/lite/executor/20180804-10727-mcs6qk/index.py", line 22, in handle
return response({'message': e.}, 400)
File "/tmp/jets/lite/executor/20180804-10727-mcs6qk/index.py", line 5, in response
badcode
NameError: global name 'badcode' is not defined
So last line has the error summary info. Other lines have stack trace after the Traceback indicator.
Example of the reproduced lambda error format:
{
"errorMessage": "'NameError' object has no attribute 'message'",
"errorType": "AttributeError",
"stackTrace": [
[
"/var/task/handlers/controllers/posts_controller/python/index.py",
22,
"handle",
"return response({'message': e.message}, 400)"
]
]
}
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/jets/poly_fun/base_executor.rb', line 86 def run_lambda_executor(event, context) interpreter = @task.lang command = %Q|#{interpreter} #{lambda_executor_script} '#{JSON.dump(event)}' '#{JSON.dump(context)}'| stdout, stderr, status = Open3.capture3(command) # puts "=> #{command}".color(:green) # puts "stdout #{stdout}" # puts "stderr #{stderr}" # puts "status #{status}" if status.success? stdout else # We'll mimic the way lambda displays an error. # $stderr.puts(stderr) # uncomment to debug error_lines = stderr.split("\n") = error_lines.pop error_type = .split(':').first error_lines.shift # remove first line that has the Traceback stack_trace = error_lines.reverse # python shows stack trace in opposite order from ruby JSON.dump( "errorMessage" => , "errorType" => error_type, # hardcode "stackTrace" => stack_trace ) end end |