-
-
Notifications
You must be signed in to change notification settings - Fork 797
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
UpdateJSON response detection from stdout in local invocations #785
UpdateJSON response detection from stdout in local invocations #785
Conversation
…allow printing of JSON before the final response
thank you @cmuto09 ! just linking another issue, which will be fixed hopefully as well: #781 btw, I was thinking of hooking into the meanwhile we can still pull this PR in, if it does fix the python (and other invocation) issues. |
@dnalborczyk direct output would be great as it'll always be fairly fragile to try to detect JSON directly off stdout. I played around a little bit with that part of the As for this PR- I'm bumping into a few issues when testing in my environment so I'm gonna poke around a bit more and let you know when it's ready |
@dnalborczyk issues resolved! Turns out I missed an |
thanks @cmuto09 ! quick question regarding your comment: // downside is that it will strip out any newlines that were supposed
// to be in the response data. do you have a failing example for that? |
@cmuto09 I've had it with the python (and likely ruby, go, etc.) bugs! I pulled in the code from: https://github.com/serverless/serverless/blob/v1.50.0/lib/plugins/aws/invokeLocal/index.js#L410 and modified it a bit. I have not checked it in yet, but will soon. Would be great if you could give it a try. handler execution time goes from: running this: https://github.com/dherault/serverless-offline/blob/master/__tests__/integration/python-big-json |
@dnalborczyk no prob- checking it out now! |
@dnalborczyk the big JSON hander works as expected! I also started writing an integration test to ensure that we return the right response when we print things ahead of the return and... it doesn't work. I think I know what's going on, so I'm going to take a pass at another better way of parsing the string. In the meantime, this still fixes the big JSON issue and makes the other issue no worse, so still a valid merge. I'll get another PR up shortly with an integration test included |
Two issues covered here:
Incorrect treatment of prints as responses
The previous JSON detection assumed that there would be one and only one valid JSON object printed to
stdout
from the process. If you printed something that looked like the response, it would often throw bad JSON exceptions and fail the invocation.An example:
would end up failing while attempting to parse the following results string:
Extra newlines in large responses
Less clarity here... looks like it has something to do with buffer chunking? In any case, I was getting corrupted JSON when newlines were inserted into the buffer at regular intervals (which corresponded exactly with buffer chunk length). I fixed it by replacing all newlines at the very end. A little hacky, and would love some input of better ways to fix it (or if I'm the only one who's had it happen)