-
Notifications
You must be signed in to change notification settings - Fork 41
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
Mitigate risk of panic on parse of remote object during console.log #1129
Conversation
0073ba8
to
2b03672
Compare
These new functions are to be used when parsing the console message which is being printed by the website under test when it used console.log. Since these are string values that will be parsed and reprinted to stdout, we don't necessarily need to parse a json string into a go object (which is the main motivation for this change). This will avoid situations where k6 browser panics and causes the test run to end due to not being able to parse a json string. Other areas of the implementation (e.g. toJSON or eval) still require a go representation of the object and they will work with the existing parse functions.
Since a string is already a string, we don't need to marshal it back to a string. This will be used when working with console messages which are printed by the website under test.
Work with parseConsoleRemoteObject so that the browser module avoids trying to unmarshal objects from json to a go object. This doesn't feel like a worthwhile operation since the string will be printed to stdout.
Work with parseConsoleRemoteObject and strings rather than any types. The page.on API works with strings so there's no need to try to parse a json object to a go object and then back to a js object.
2b03672
to
53d4730
Compare
53d4730
to
2b028d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Nice work. Just some suggestions.
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
This log is notifying the user of something that can't be changed or actioned on, so it's better represented as info rather than a warn.
This is just to clarify why these empty cases are there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
It's no longer being used.
df89ca4
to
dbb0981
Compare
This particular test may run slower on other machines, so accounting for that scenario -- specifically in the CI.
dbb0981
to
1a76aec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
What?
This change reduces the risk of a panic occurring when the website under test uses
console.log
to print logs.Why?
Currently there is an unknown case where a panic can occur when an object from console.log is unmarshaled and fails with an invalid JSON error. So this isn't fixing the issue but mitigating the risk. This is done by not needing to parse the console.log text at all. The reason behind this choice is that when a user prints something to the console, they don't tend to need the object to be parsed.
Other areas of the module still rely on the existing parse logic which does still attempt to unmarshal the object which is returned when working with APIs such as
JSONValue
andEval
.Checklist
Related PR(s)/Issue(s)
Updates: #987