Skip to content
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

Merged
merged 5 commits into from
Mar 29, 2018

Conversation

luizbafilho
Copy link
Contributor

@luizbafilho luizbafilho commented Mar 28, 2018

Closes #543

@codecov-io
Copy link

codecov-io commented Mar 28, 2018

Codecov Report

Merging #563 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
js/runner.go 81.48% <100%> (+0.4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e50dea...67d660f. Read the comment docs.

Copy link
Member

@robingustafsson robingustafsson left a 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"))
Copy link
Member

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

Copy link
Member

@na-- na-- left a 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

@luizbafilho luizbafilho merged commit 07dee4b into master Mar 29, 2018
@luizbafilho luizbafilho deleted the fix/better-error-open branch March 29, 2018 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants