stepci: [Bug]: UnhandledPromiseRejection in posthog-node 2.2.1

What happened?

When I run the test using the stepci CLI, the test itself succeeds, but then I get an error UnhandledPromiseRejection.

$ stepci run ./workflow.yml
 PASS  example

Tests: 0 failed, 1 passed, 1 total
Steps: 0 failed, 1 passed, 1 total
Time:  0.109s, estimated 0s

Workflow passed after 0.109s
Give us your feedback on https://step.ci/feedback
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "CanceledError: canceled".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

workflow.yml:

version: "1.1"
name: Validating JSON

config:
  http:
    baseURL: https://jsonplaceholder.typicode.com

env:
  postId: "2"

tests:
  example:
    steps:
      - name: GET request
        http:
          url: /posts/${{env.postId}}
          method: GET
          check:
            status: 200
            jsonpath:
              $.id: ${{env.postId}}
              $.userId: 1

The same error occurs when using github actions. logs: https://github.com/koki-develop/stepci-example/actions/runs/3551276044/jobs/5965323631 .github/workflows/main.yml:

name: api test

on:
  push:

jobs:
  with-action:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: stepci/stepci@main
        with:
          workflow: workflow.yml

This error does not occur when using @stepci/runner, so there may be some problem with stepci cli. The workflow below uses @stepci/runner in vitest, but no error occurs.

logs: https://github.com/koki-develop/stepci-example/actions/runs/3551276044/jobs/5965323586

What did you expect to happen?

After the test is completed, it ends without error as it is.

Version

2.5.1

Environment

Node v16.18.1

How can we reproduce this bug?

commands:

$ git clone git@github.com:koki-develop/stepci-example.git
$ cd stepci-example
$ stepci run ./workflow.yml

output:

 PASS  example

Tests: 0 failed, 1 passed, 1 total
Steps: 0 failed, 1 passed, 1 total
Time:  0.132s, estimated 0s

Workflow passed after 0.132s
Give us your feedback on https://step.ci/feedback
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "CanceledError: canceled".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

exit code:

$ echo $?
1

Relevant log output

PASS  example

Tests: 0 failed, 1 passed, 1 total
Steps: 0 failed, 1 passed, 1 total
Time:  0.132s, estimated 0s

Workflow passed after 0.132s
Give us your feedback on https://step.ci/feedback
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "CanceledError: canceled".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Would you be interested in working on a bugfix for this issue?

  • Yes! Assign me

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (22 by maintainers)

Commits related to this issue

Most upvoted comments

Done, thank you so much! Now you’re one of us, officially: https://github.com/stepci/stepci/graphs/contributors

😍

Hey @koki-develop, can I ask you for a small thing? Could you update posthog-node in our package.json to ^2.2.2 and open a Pull Request?

The reason I’m asking is because I’d like to give you a credit for your work on the issue πŸ˜‰

Screenshot 2022-11-28 at 17 31 10

Thank you very much

No worries, I’ll fill the report and reference you there. Please update stepci to 2.5.5 Thanks for looking into it πŸ™

Thanks to you for finding the bug and filling the issue! Was a pleasure to help πŸ˜‰

I just upgraded stepci to version 2.5.5 and the error no longer occurs! πŸ™†β€β™‚οΈ Thanks for the quick response! ❀️

Resolved! posthog allows a timeout to be set when sending a request, and the default timeout value is 10ms.

https://github.com/PostHog/posthog-js-lite/blob/7b26cde29a2e18ac23681128ae64fcd918c09597/posthog-core/src/index.ts#L71

The request itself was successfully sent, but because it took more than 10 ms, it is considered a failure and this error occurs. I was able to avoid this error by setting a longer timeout when initializing the PostHog instance.

I’ll create a Pull Request! πŸ™‹β€β™‚οΈ

The error happens after posthog.shutdown() in lib/analytics.ts is called

Getting the same error on my local environment now

I just tried it with the latest v2.5.4 and found something new. The same error still occurs, but when I set the STEPCI_DISABLE_ANALYTICS environment variable, the error did not occur. Something may be happening where data is being sent to posthog πŸ€”

$ stepci --version
2.5.4
$ stepci run ./workflow.yml

β“˜  Anonymous usage data collected. Learn more on https://step.ci/privacy

 PASS  example

Tests: 0 failed, 1 passed, 1 total
Steps: 0 failed, 0 skipped, 1 passed, 1 total
Time:  0.107s, estimated 0s

Workflow passed after 0.107s
Give us your feedback on https://step.ci/feedback
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "CanceledError: canceled".] {
  code: 'ERR_UNHANDLED_REJECTION'
}
$ export STEPCI_DISABLE_ANALYTICS=1
$ stepci run ./workflow.yml
 PASS  example

Tests: 0 failed, 1 passed, 1 total
Steps: 0 failed, 0 skipped, 1 passed, 1 total
Time:  0.096s, estimated 0s

Workflow passed after 0.096s
Give us your feedback on https://step.ci/feedback