-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Better error message when using the open function outside init code #563
Conversation
Codecov Report
@@ Coverage Diff @@
## master #563 +/- ##
==========================================
+ Coverage 62.89% 62.91% +0.02%
==========================================
Files 96 96
Lines 7217 7221 +4
==========================================
+ Hits 4539 4543 +4
Misses 2429 2429
Partials 249 249
Continue to review full report at Codecov.
|
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.
I think we should rephrase the error message, but otherwise it LGTM.
js/runner.go
Outdated
@@ -172,6 +172,11 @@ func (r *Runner) newVU() (*VU, error) { | |||
BPool: bpool.NewBufferPool(100), | |||
} | |||
vu.Runtime.Set("console", common.Bind(vu.Runtime, vu.Console, vu.Context)) | |||
common.BindToGlobal(vu.Runtime, map[string]interface{}{ | |||
"open": func() { | |||
common.Throw(vu.Runtime, errors.New("open function it is only available at init code")) |
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.
I'd rephrase the error message as:
"open" function is only available to the init code (aka global scope), see https://docs.k6.io/docs/test-life-cycle for more information
I think including a link to the docs is helpful, but it of course adds some burden on us to make sure those links keep working if we change the URL
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, though a unit test that verifies this works as expected will also be good
Closes #543