fix: Don't override Ruby stdout
with stderr
#1336
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR prevents from
stdout
from being replaced withstderr
in responses from Ruby handlers.Motivation and Context
When I run my Ruby handler (which uses serverless-rack to run a Sinatra application, I noticed that whenever I add a logging statement (such as
puts
orlogger.info
), the response from my handler no longer shows in my browser. Instead, I get the logs in my browser (in addition to the console).Same thing happens when there's an uncaught error. My app's error page is bypassed, and instead my error logs are printed to the browser.
I found out that this is because Rack's error stream is stderr (as it should be), and these lines in this project:
serverless-offline/src/lambda/handler-runner/ruby-runner/RubyRunner.js
Lines 105 to 115 in febfe77
return stderr as the response when it is non-empty. But there is no good reason for this. The framework's own guide says plugins should write logs (not just errors) to stderr and output to stdout, so it makes no sense to sometimes return the logs instead of the output. Also, the other runners don't do this.
How Has This Been Tested?
I pointed my local app to this change, and it worked as expected. My response is always returned, and logs remain on the console only.