GoError: running at go.k6.io/k6/js/modules/k6.(*K6).Fail-fm (native)

I’m not sure exactly what I’m doing wrong here;

Snippet of code:

    import { check, group, fail } from 'k6';

    ...

    const res = http.post(url, payload, { headers });
    const succeeded = res.json('succeeded') === true;
    const message = res.json('message');
    CounterErrors.add(!succeeded);
    check(res, {
      'response code was 200': (r) => r.status === 200,
      'succeeded is true': (r) => succeeded,
    }) || fail(`status was not 200 or it failed. Message: ${message}`);

    duration.add(res.timings.duration, { my_tag: 'Duration' });
    waiting.add(res.timings.waiting, { my_tag: 'Waiting' });

  });

What I want it to do is:

  • to check there is a 200 HTTP code and to check the JSON response for “succeeded: true”
  • when one of those conditions fails, I want it to show an error message of “status was not 200 or it failed. Message:[then the actual error message]`”

Now it does both of those but I get a GoError mixed in for good luck:

ERRO[0002] GoError: status was not 200 or it failed. Message: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy.
running at go.k6.io/k6/js/modules/k6.(*K6).Fail-fm (native)
default at file:///C:/Users/bob/desktop/test.js:55:16(86)
        at go.k6.io/k6/js/modules/k6.(*K6).Group-fm (native)
        at file:///C:/Users/bob/desktop/test.js:27:8(6)  executor=shared-iterations scenario=default source=stacktrace

I’m guessing the GoError shouldn’t be there? Any idea what I’m doing wrong?
Edit: just to say, ignore the “An exception has been raised…” that is an error my side.

Thanks!!

Hi there!

I’m not sure what you were expecting, since this seems to be working fine from what I can see.

It seems that one of those checks failed, so fail() was called correctly, which caused the iteration to be aborted, and your message to be printed. That GoError message and stack trace is the expected behavior of k6.fail(). GoError is slightly confusing, but it’s because of an underlying reason with how errors are handled in k6.

If you don’t want to abort the iteration, or to print the stack trace, you can use console.error() instead.

1 Like

It works; it’s just I wasn’t perhaps expecting the GoError to be thrown in for good measure. It’s presence makes me question if I am doing something wrong.

I just assumed it would simply show only this status was not 200 or it failed. Message: ${message} with nothing else rather than adding in a GoError too.

Essentially, of this is superfluous to me, but it being shown, made me think I was doing something wrong.

running at go.k6.io/k6/js/modules/k6.(*K6).Fail-fm (native)
default at file:///C:/Users/bob/desktop/test.js:55:16(86)
        at go.k6.io/k6/js/modules/k6.(*K6).Group-fm (native)
        at file:///C:/Users/bob/desktop/test.js:27:8(6)  executor=shared-iterations scenario=default source=stacktrace

If it’s expected, then fair enough.