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

oidc/init: include cause in re-thrown errors #1393

Merged
merged 3 commits into from
Feb 21, 2025

Conversation

alxndrsn
Copy link
Contributor

@alxndrsn alxndrsn commented Feb 10, 2025

Noted while working on #1230.

This makes logged errors more useful.

Example logging

Before

attempted to log Sentry exception in development:
Error: Failed to configure OpenID Connect client: TypeError: fetch failed
    at initClient (/home/user/workspaces/odk/backend/lib/util/oidc.js:123:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/user/workspaces/odk/backend/lib/resources/oidc.js:108:22

After

attempted to log Sentry exception in development:
Error: Failed to configure OpenID Connect client
    at initClient (/home/user/workspaces/odk/backend/lib/util/oidc.js:123:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/user/workspaces/odk/backend/lib/resources/oidc.js:108:22 {
  [cause]: TypeError: fetch failed
      at node:internal/deps/undici/undici:13484:13
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async discovery (file:///home/user/workspaces/odk/backend/node_modules/openid-client/build/index.js:151:16)
      at async initClient (/home/user/workspaces/odk/backend/lib/util/oidc.js:65:20)
      at async /home/user/workspaces/odk/backend/lib/resources/oidc.js:108:22 {
    [cause]: Error: connect ECONNREFUSED 127.0.0.1:9898
        at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1615:16) {
      errno: -111,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 9898
    }
  }
}

What has been done to verify that this works as intended?

Run locally & run tests.

Why is this the best possible solution? Were any other approaches considered?

No other approaches were considered.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

This change should only affect environments with Sentry disabled. If third-party deployments are parsing stderr for e.g. monitoring, this may affect them.

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

This change does not affect the public API.

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

alxndrsn and others added 2 commits February 10, 2025 06:57
This makes logged errors more useful.

Before:

```
attempted to log Sentry exception in development:
Error: Failed to configure OpenID Connect client: TypeError: fetch failed
    at initClient (/home/user/workspaces/odk/backend/lib/util/oidc.js:123:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/user/workspaces/odk/backend/lib/resources/oidc.js:108:22
```

After:

```
attempted to log Sentry exception in development:
Error: Failed to configure OpenID Connect client
    at initClient (/home/user/workspaces/odk/backend/lib/util/oidc.js:123:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/user/workspaces/odk/backend/lib/resources/oidc.js:108:22 {
  [cause]: TypeError: fetch failed
      at node:internal/deps/undici/undici:13484:13
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async discovery (file:///home/user/workspaces/odk/backend/node_modules/openid-client/build/index.js:151:16)
      at async initClient (/home/user/workspaces/odk/backend/lib/util/oidc.js:65:20)
      at async /home/user/workspaces/odk/backend/lib/resources/oidc.js:108:22 {
    [cause]: Error: connect ECONNREFUSED 127.0.0.1:9898
        at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1615:16) {
      errno: -111,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 9898
    }
  }
}
```
@alxndrsn alxndrsn mentioned this pull request Feb 10, 2025
2 tasks
@alxndrsn alxndrsn requested a review from ktuite February 12, 2025 05:44
@matthew-white
Copy link
Member

Looks good to me. 👍

@alxndrsn alxndrsn merged commit c547dfc into getodk:master Feb 21, 2025
6 checks passed
@alxndrsn alxndrsn deleted the oidc-error-clarity branch February 21, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ done
Development

Successfully merging this pull request may close these issues.

2 participants