grafana / k6

A modern load testing tool, using Go and JavaScript - https://k6.io
GNU Affero General Public License v3.0
25.16k stars 1.25k forks source link

`setup()` and `teardown()` errors are not logged when invoked from REST API #2422

Closed na-- closed 1 year ago

na-- commented 2 years ago

If you run this script:

export const options = {
    paused: true,
};

export function setup() {
    console.log('foo')
    throw new Error('bar');
}

export default function (data) {
}

And execute curl -iX POST 'http://localhost:6565/v1/setup' in another terminal, you would not see the script error bar in the terminal, but you'd see foo.

kmtym1998 commented 1 year ago

@na-- I tried to reproduce to fix this bug, but it seems to be fixed.

# Run your script
$ k6 run script.js

# execute curl (in another terminal)
$ curl -iX POST 'http://localhost:6565/v1/setup'
HTTP/1.1 500 Internal Server Error
Date: Fri, 18 Aug 2023 02:17:52 GMT
Content-Length: 158
Content-Type: text/plain; charset=utf-8
{
  "errors": [
    {
      "status": "500",
      "title": "Error executing setup",
      "detail": "Error: bar\n\tat setup (file:///XXX/XXX/script.js:7:8(8))\n"
    }
  ]
}

# my k6 version
$ k6 version  
k6 v0.46.0 ((devel), go1.21.0, darwin/arm64)
mstoykov commented 1 year ago

@kmtym1998 I think the idea @na-- had was that it should also print the exception in the k6 output, not just in the response to curl

kmtym1998 commented 1 year ago

@mstoykov

I see. I would like to try to fix this. Can I work on?