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

Example with Return error instead of killing process doesn't work #25

Closed
jokuniew opened this issue Jul 30, 2024 · 8 comments
Closed

Example with Return error instead of killing process doesn't work #25

jokuniew opened this issue Jul 30, 2024 · 8 comments
Assignees

Comments

@jokuniew
Copy link

jokuniew commented Jul 30, 2024

I've built and installed k6 with latest xk6-exec

k6 v0.52.0 (go1.22.0, linux/amd64)
Extensions:
  github.com/grafana/xk6-exec v0.4.0, k6/x/exec [js]

then run k6 run examples/script.js the example introduced in #24

the output i get

INFO[0000] Tue Jul 30 01:21:29 PM UTC 2024               source=console
INFO[0000] 2024/07/30 13:21:29 exit status 2 on command: ls -a NO_SUCH_DIR 

I expected to see logs like "ERROR: " or "STDERR: " in this example but actually my test panic and stopped.

I can't handle exec.command errors in try catch statement

@pablochacin @vvakar

@jokuniew jokuniew changed the title Examples with Return error instead of killing process doesn't work Example with Return error instead of killing process doesn't work Jul 30, 2024
@vvakar
Copy link
Contributor

vvakar commented Jul 31, 2024

I noticed that too, and would like to know the answer. For the time being, I'm able to build by pointing to the specific commit, in case it helps:

xk6 build --with github.com/grafana/xk6-exec@d9fdfce4ac85e6f0c42100794b0e51047f5dd0f6

@pablochacin pablochacin self-assigned this Sep 2, 2024
@pablochacin
Copy link
Contributor

@jokuniew @vvakar I can't reproduce the error you mention.

The example is working as expected. The command executed with the continue_on_error option does not abort the test, but the last one, which does not use this option, aborts it.

$ k6 version
k6 v0.51.0 (go1.22.4, linux/amd64)
Extensions:
  github.com/grafana/xk6-exec v0.4.0, k6/x/exec [js]


$k6 run examples/script.js
....
INFO[0000] lun 02 sep 2024 20:03:26 CEST                 source=console
INFO[0000] ERROR: GoError: exit status 2                 source=console
INFO[0000] STDERR: ls: cannot access 'NO_SUCH_DIR': No such file or directory  source=console
INFO[0000] 2024/09/02 20:03:26 chdir sub-directory: no such file or directory on command: ls -a -l 

@vvakar
Copy link
Contributor

vvakar commented Sep 3, 2024

@pablochacin It's very curious. I pasted the full terminal log below showing that the 0.4.0 version is somehow missing the fix, but the specific commit has it:

$ xk6 build --with github.com/grafana/xk6-exec
...
cmdradmin@cmdr-testing:~/xk6-exec$ ./k6 version
k6 v0.51.0 (go1.22.4, linux/amd64)
Extensions:
  github.com/grafana/xk6-exec v0.4.0, k6/x/exec [js]


cmdradmin@cmdr-testing:~/xk6-exec$ ./k6 run examples/script.js

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

     execution: local
        script: examples/script.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
              * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] Tue Sep  3 09:14:17 UTC 2024                  source=console
INFO[0000] 2024/09/03 09:14:17 exit status 2 on command: ls -a NO_SUCH_DIR

-----------------------------------------------------------------------------------


cmdradmin@cmdr-testing:~/xk6-exec$ xk6 build --with github.com/grafana/xk6-exec@d9fdfce4ac85e6f0c42100794b0e51047f5dd0f6
...

cmdradmin@cmdr-testing:~/xk6-exec$ ./k6 version
k6 v0.51.0 (go1.22.4, linux/amd64)
Extensions:
  github.com/grafana/xk6-exec v0.3.1-0.20240709114410-d9fdfce4ac85, k6/x/exec [js]


cmdradmin@cmdr-testing:~/xk6-exec$ ./k6 run examples/script.js

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

     execution: local
        script: examples/script.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
              * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] Tue Sep  3 09:14:50 UTC 2024                  source=console
INFO[0000] ERROR: GoError: exit status 2                 source=console
INFO[0000] STDERR: ls: cannot access 'NO_SUCH_DIR': No such file or directory  source=console
INFO[0000] 2024/09/03 09:14:50 chdir sub-directory: no such file or directory on command: ls -a -l

@jokuniew
Copy link
Author

jokuniew commented Sep 3, 2024

To avoid any golang/binary misconfiguration I've tried to use xk6 through docker image with v0.51.0 k6 just like @pablochacin has and still the same behavior occurs
docker run --rm -it -u "$(id -u):$(id -g)" -v "${PWD}:/xk6" grafana/xk6 build v0.51.0 --with github.com/grafana/xk6-exec@v0.4.0

./k6 version
k6 v0.51.0 (go1.22.4, linux/amd64)
Extensions:
  github.com/grafana/xk6-exec v0.4.0, k6/x/exec [js]
./k6 run examples/script.js 

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

     execution: local
        script: examples/script.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
              * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] Tue Sep  3 09:08:04 AM UTC 2024               source=console
INFO[0000] 2024/09/03 09:08:04 exit status 2 on command: ls -a NO_SUCH_DIR

@pablochacin
Copy link
Contributor

pablochacin commented Sep 4, 2024

@vvakar @jokuniew Apparently, v0.4.0 was corrupted in the goland proxy cache. I released v0.4.1 which introduces no changes, but generates a new entry in the proxy's cache. Thos should fix the use.

@vvakar
Copy link
Contributor

vvakar commented Sep 4, 2024

v0.4.1 works, thanks!! :)

@pablochacin
Copy link
Contributor

Fixed in release v0.4.1

@jokuniew
Copy link
Author

jokuniew commented Sep 5, 2024

I can also confirm that v0.4.1 works fine. Thanks @pablochacin ! ;)

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

No branches or pull requests

3 participants