[GH-ISSUE #4150] Tests on canary are failing #9838

Closed
opened 2026-04-13 05:35:33 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @dvanmali on GitHub (Aug 22, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4150

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Run any test. For example:

pnpm test src/plugins/jwt/jwt.test.ts
# SERVER_ERROR:  TypeError: Cannot read properties of undefined (reading 'stack')
    at api.<computed> (.../better-auth/packages/better-auth/src/api/to-auth-endpoints.ts:125:60)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at processRequest (.../better-auth/node_modules/better-call/src/router.ts:194:22)
    at handler (.../better-auth/node_modules/better-call/src/router.ts:215:16)
    at betterFetch (.../better-auth/node_modules/@better-fetch/fetch/src/fetch.ts:77:17)
    at $fetch (.../better-auth/node_modules/@better-fetch/fetch/src/create-fetch/index.ts:95:10)
    at Object.apply (.../better-auth/packages/better-auth/src/client/proxy.ts:80:12)
    at .../better-auth/packages/better-auth/src/plugins/oauth-provider/register.test.ts:57:20
    at .../better-auth/node_modules/@vitest/runner/dist/chunk-hooks.js:752:20

Current vs. Expected behavior

Began within the past ~15 commits

Traced to PR #4094

What version of Better Auth are you using?

canary

Originally created by @dvanmali on GitHub (Aug 22, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4150 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Run any test. For example: ```sh pnpm test src/plugins/jwt/jwt.test.ts ``` ``` # SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'stack') at api.<computed> (.../better-auth/packages/better-auth/src/api/to-auth-endpoints.ts:125:60) at processTicksAndRejections (node:internal/process/task_queues:105:5) at processRequest (.../better-auth/node_modules/better-call/src/router.ts:194:22) at handler (.../better-auth/node_modules/better-call/src/router.ts:215:16) at betterFetch (.../better-auth/node_modules/@better-fetch/fetch/src/fetch.ts:77:17) at $fetch (.../better-auth/node_modules/@better-fetch/fetch/src/create-fetch/index.ts:95:10) at Object.apply (.../better-auth/packages/better-auth/src/client/proxy.ts:80:12) at .../better-auth/packages/better-auth/src/plugins/oauth-provider/register.test.ts:57:20 at .../better-auth/node_modules/@vitest/runner/dist/chunk-hooks.js:752:20 ``` ### Current vs. Expected behavior Began within the past ~15 commits Traced to PR #4094 ### What version of Better Auth are you using? canary
GiteaMirror added the lockedbug labels 2026-04-13 05:35:34 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 22, 2025):

The test failures on canary are caused by code in to-auth-endpoints.ts that tries to access errorWithStack.stack without checking if errorWithStack is defined. This happens in several places, including line 125 and inside hook runners. If errorWithStack is undefined, you'll get a TypeError: Cannot read properties of undefined (reading 'stack') source.

Recent PRs (#4091 and #4094) changed error stack handling and likely introduced this regression. To fix it, add guard clauses before accessing errorWithStack.stack, for example:

if (
  result.response instanceof APIError &&
  shouldPublishLog(authContext.logger.level, "debug") &&
  result.response.errorWithStack?.stack
) {
  result.response.stack = result.response.errorWithStack.stack;
}

Apply similar checks anywhere you assign from errorWithStack.stack to prevent runtime errors. This will make error handling robust and resolve the test failures.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3213345461 --> @dosubot[bot] commented on GitHub (Aug 22, 2025): <!-- Answer --> The test failures on canary are caused by code in `to-auth-endpoints.ts` that tries to access `errorWithStack.stack` without checking if `errorWithStack` is defined. This happens in several places, including line 125 and inside hook runners. If `errorWithStack` is undefined, you'll get a `TypeError: Cannot read properties of undefined (reading 'stack')` [source](https://github.com/better-auth/better-auth/blob/fe9c5e428b0a11ec3217bf9c66db978cf54f7ad8/packages/better-auth/src/api/to-auth-endpoints.ts). Recent PRs (#4091 and #4094) changed error stack handling and likely introduced this regression. To fix it, add guard clauses before accessing `errorWithStack.stack`, for example: ```ts if ( result.response instanceof APIError && shouldPublishLog(authContext.logger.level, "debug") && result.response.errorWithStack?.stack ) { result.response.stack = result.response.errorWithStack.stack; } ``` Apply similar checks anywhere you assign from `errorWithStack.stack` to prevent runtime errors. This will make error handling robust and resolve the test failures. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/50cc16e0-aa10-4997-8d80-9699f34fdd52?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/50cc16e0-aa10-4997-8d80-9699f34fdd52?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/50cc16e0-aa10-4997-8d80-9699f34fdd52?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/50cc16e0-aa10-4997-8d80-9699f34fdd52?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/50cc16e0-aa10-4997-8d80-9699f34fdd52?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/50cc16e0-aa10-4997-8d80-9699f34fdd52?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/50cc16e0-aa10-4997-8d80-9699f34fdd52?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4150)
Author
Owner

@NalinDalal commented on GitHub (Aug 22, 2025):

uhh, can i approach this one?

<!-- gh-comment-id:3213729269 --> @NalinDalal commented on GitHub (Aug 22, 2025): uhh, can i approach this one?
Author
Owner

@Kinfe123 commented on GitHub (Aug 22, 2025):

please make sure to update better-call to the latest and do pnpm install

<!-- gh-comment-id:3214329123 --> @Kinfe123 commented on GitHub (Aug 22, 2025): please make sure to update better-call to the latest and do pnpm install
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9838