Skip to content

fix: Improve post-dataloader stack traces.#1384

Merged
stephenh merged 1 commit into
mainfrom
better-stack-traces
Mar 1, 2025
Merged

fix: Improve post-dataloader stack traces.#1384
stephenh merged 1 commit into
mainfrom
better-stack-traces

Conversation

@stephenh

@stephenh stephenh commented Feb 23, 2025

Copy link
Copy Markdown
Collaborator

Any time a batched operation fails, it will fail in "the other context" / the dataloader's setTimeout-d callback, where the error.stack doesn't know about the caller-who-is-blocking's context/stack.

And so it's error.stack will not include the caller's own stack:

error: SELECT a.* FROM authors AS a WHERE a.id = $1 ORDER BY a.id ASC LIMIT $2 - invalid input syntax for type integer: "0.6931471805599453"
    at Object.raw (/home/stephen/other/joist-orm/node_modules/knex/lib/knex-builder/make-knex.js:116:30)
    at Function.value (/home/stephen/other/joist-orm/node_modules/knex/lib/knex-builder/make-knex.js:92:29)
    at PostgresDriver.executeQuery (/home/stephen/other/joist-orm/packages/orm/src/drivers/PostgresDriver.ts:69:8)
    at PostgresDriver.executeFind (/home/stephen/other/joist-orm/packages/orm/src/drivers/PostgresDriver.ts:63:17)
    at DataLoader.em.getLoader.cacheKeyFn [as _batchLoadFn] (/home/stephen/other/joist-orm/packages/orm/src/dataloaders/findDataLoader.ts:61:38)
    at dispatchBatch (/home/stephen/other/joist-orm/node_modules/dataloader/index.js:288:27)
    at /home/stephen/other/joist-orm/node_modules/dataloader/index.js:268:5
    at processTicksAndRejections (node:internal/process/task_queues:85:11)

We can only tell "someone asked the dataloader to batch this".

With the appendStack, we see who the caller was:

error: SELECT a.* FROM authors AS a WHERE a.id = $1 ORDER BY a.id ASC LIMIT $2 - invalid input syntax for type integer: "0.6931471805599453"
    at Object.raw (/home/stephen/other/joist-orm/node_modules/knex/lib/knex-builder/make-knex.js:116:30)
    at Function.value (/home/stephen/other/joist-orm/node_modules/knex/lib/knex-builder/make-knex.js:92:29)
    at PostgresDriver.executeQuery (/home/stephen/other/joist-orm/packages/orm/src/drivers/PostgresDriver.ts:69:8)
    at PostgresDriver.executeFind (/home/stephen/other/joist-orm/packages/orm/src/drivers/PostgresDriver.ts:63:17)
    at DataLoader.em.getLoader.cacheKeyFn [as _batchLoadFn] (/home/stephen/other/joist-orm/packages/orm/src/dataloaders/findDataLoader.ts:61:38)
    at dispatchBatch (/home/stephen/other/joist-orm/node_modules/dataloader/index.js:288:27)
    at /home/stephen/other/joist-orm/node_modules/dataloader/index.js:268:5
    at processTicksAndRejections (node:internal/process/task_queues:85:11)
    at find (/home/stephen/other/joist-orm/packages/orm/src/EntityManager.ts:331:32) <== new lines
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at EntityManager.find (/home/stephen/other/joist-orm/packages/orm/src/EntityManager.ts:328:20)
    at Object.<anonymous> (/home/stephen/other/joist-orm/packages/tests/integration/src/EntityManager.queries.test.ts:76:21)

Fixes #1383

Any time a batched operation fails, it will fail in "the other context",
where the error.stack doesn't know about the caller-who-is-blocking's
context/stack.

And so it's error.stack will not include the caller's own stack:

```
error: SELECT a.* FROM authors AS a WHERE a.id = $1 ORDER BY a.id ASC LIMIT $2 - invalid input syntax for type integer: "0.6931471805599453"
    at Object.raw (/home/stephen/other/joist-orm/node_modules/knex/lib/knex-builder/make-knex.js:116:30)
    at Function.value (/home/stephen/other/joist-orm/node_modules/knex/lib/knex-builder/make-knex.js:92:29)
    at PostgresDriver.executeQuery (/home/stephen/other/joist-orm/packages/orm/src/drivers/PostgresDriver.ts:69:8)
    at PostgresDriver.executeFind (/home/stephen/other/joist-orm/packages/orm/src/drivers/PostgresDriver.ts:63:17)
    at DataLoader.em.getLoader.cacheKeyFn [as _batchLoadFn] (/home/stephen/other/joist-orm/packages/orm/src/dataloaders/findDataLoader.ts:61:38)
    at dispatchBatch (/home/stephen/other/joist-orm/node_modules/dataloader/index.js:288:27)
    at /home/stephen/other/joist-orm/node_modules/dataloader/index.js:268:5
    at processTicksAndRejections (node:internal/process/task_queues:85:11)
```

We can only tell "someone asked the dataloader to batch this".

With the appendStack, we see who the caller was:

```
error: SELECT a.* FROM authors AS a WHERE a.id = $1 ORDER BY a.id ASC LIMIT $2 - invalid input syntax for type integer: "0.6931471805599453"
    at Object.raw (/home/stephen/other/joist-orm/node_modules/knex/lib/knex-builder/make-knex.js:116:30)
    at Function.value (/home/stephen/other/joist-orm/node_modules/knex/lib/knex-builder/make-knex.js:92:29)
    at PostgresDriver.executeQuery (/home/stephen/other/joist-orm/packages/orm/src/drivers/PostgresDriver.ts:69:8)
    at PostgresDriver.executeFind (/home/stephen/other/joist-orm/packages/orm/src/drivers/PostgresDriver.ts:63:17)
    at DataLoader.em.getLoader.cacheKeyFn [as _batchLoadFn] (/home/stephen/other/joist-orm/packages/orm/src/dataloaders/findDataLoader.ts:61:38)
    at dispatchBatch (/home/stephen/other/joist-orm/node_modules/dataloader/index.js:288:27)
    at /home/stephen/other/joist-orm/node_modules/dataloader/index.js:268:5
    at processTicksAndRejections (node:internal/process/task_queues:85:11)
    at find (/home/stephen/other/joist-orm/packages/orm/src/EntityManager.ts:331:32) <== new lines
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at EntityManager.find (/home/stephen/other/joist-orm/packages/orm/src/EntityManager.ts:328:20)
    at Object.<anonymous> (/home/stephen/other/joist-orm/packages/tests/integration/src/EntityManager.queries.test.ts:76:21)
```
@stephenh stephenh merged commit 62740e4 into main Mar 1, 2025
stephenh pushed a commit that referenced this pull request Mar 1, 2025
## [1.228.9](v1.228.8...v1.228.9) (2025-03-01)

### Bug Fixes

* Improve post-dataloader stack traces. ([#1384](#1384)) ([62740e4](62740e4))
@stephenh

stephenh commented Mar 1, 2025

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 1.228.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stephenh stephenh deleted the better-stack-traces branch March 3, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve stack traces

1 participant