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

[Feature Request]: Stop execution when Javascript error encountered #2207

Closed
uykusuz opened this issue Oct 29, 2021 · 2 comments
Closed

[Feature Request]: Stop execution when Javascript error encountered #2207

uykusuz opened this issue Oct 29, 2021 · 2 comments
Labels

Comments

@uykusuz
Copy link

uykusuz commented Oct 29, 2021

Feature Description

If I write something like the following and run it:

export default function() { hurz }

k6 will write an error to the console like the following:
ERRO[0000] ReferenceError: hurz is not defined

But will exit normally and print out the usual statistics.

I couldn't find a way to tell k6 to exit abnormally if it encounters an error like this. Is there a way to tell k6 to do this?

Suggested Solution (optional)

Add a configuration option to make k6 exit non-zero if it encounters Javascript errors during execution.

@na--
Copy link
Member

na-- commented Oct 29, 2021

Thanks for creating this issue! We've considered something like this before, though mostly intended for non-syntax script errors (e.g. trying to use the body of a response for a failed request without checking it), see #877. From what I understand, you'd like k6 to exit on the first such script error it sees, right?

As a workaround right now, you can add a custom Counter metric, surround your code with a try {} catch() {} block and increment the counter in the catch. Then, if you have a threshold on the new metric with abortOnFail, k6 will abort the test script after you increment the counter. Though not immediately, k6 evaluates thresholds every 2 seconds.

Soon, when we merge #2093 (either in the upcoming k6 v0.35.0 or v0.36.0), we'll have a way to immediately abort the whole script, so there won't be a need for the threshold (you'd still need the try/catch block though)...

@uykusuz
Copy link
Author

uykusuz commented Oct 29, 2021

thanks for the fast response! That works.

@uykusuz uykusuz closed this as completed Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants