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

Fix stack traces when using EntityPersistExecutor #7218

Merged
merged 1 commit into from
Jan 11, 2021
Merged

Fix stack traces when using EntityPersistExecutor #7218

merged 1 commit into from
Jan 11, 2021

Conversation

bogdan
Copy link
Contributor

@bogdan bogdan commented Dec 23, 2020

Description of change

Floating promises are causing issues with lost stack traces. Summary of a change:

+        await Promise.resolve();
+       // do whatever
-        return Promise.resolve().then(async () => {
-          // do whatever
-       });

This hack was added in a4e5abe and related tests are passing.

Example

Old stack trace in my app:

     ObjectInvalid: An instance of Domain has failed the validation:
      at Domain.validateOrReject (lib/entities/Model.ts:171:13)

New stack trace in my app:

     ObjectInvalid: An instance of Domain has failed the validation:
      at Domain.validateOrReject (lib/entities/Model.ts:171:13)
      at Domain.captureStack (lib/entities/Model.ts:163:19)
      at EntityListenerMetadata.execute (src/metadata/EntityListenerMetadata.ts:71:45)
      at /Users/bogdan/makabu/unstoppable/unstoppable-domains-website/default/src/subscriber/Broadcaster.ts:38:54
      at Array.forEach (<anonymous>)
      at Broadcaster.broadcastBeforeInsertEvent (src/subscriber/Broadcaster.ts:36:44)
      at /Users/bogdan/makabu/unstoppable/unstoppable-domains-website/default/src/persistence/SubjectExecutor.ts:210:81
      at Array.forEach (<anonymous>)
      at SubjectExecutor.broadcastBeforeEventsForAll (src/persistence/SubjectExecutor.ts:210:33)
      at SubjectExecutor.<anonymous> (src/persistence/SubjectExecutor.ts:107:38)
      at step (node_modules/typeorm/node_modules/tslib/tslib.js:141:27)
      at Object.next (node_modules/typeorm/node_modules/tslib/tslib.js:122:57)
      at /Users/bogdan/makabu/unstoppable/unstoppable-domains-website/default/node_modules/typeorm/node_modules/tslib/tslib.js:115:75
      at new Promise (<anonymous>)
      at Object.__awaiter (node_modules/typeorm/node_modules/tslib/tslib.js:111:16)
      at SubjectExecutor.execute (node_modules/typeorm/persistence/SubjectExecutor.js:67:24)
      at EntityPersistExecutor_1.EntityPersistExecutor.execute (lib/connect.ts:226:26)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at Context.<anonymous> (lib/entities/Model.test.ts:20:5)

I was trying to make a test for an error stack to be full, but unfortunately it is only testable when typescript compiler option is set to es2018 or above. Your target is es5 which is too low for it even to be testable.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

@bogdan bogdan changed the title Improve stack traces when using EntityPersistExecutor Fix stack traces when using EntityPersistExecutor Dec 23, 2020
@nebkat
Copy link
Contributor

nebkat commented Jan 9, 2021

Looks good, if you can just add fix: in front of the commit title as per CONTRIBUTING.md.

@pleerock pleerock merged commit 0dfe5b8 into typeorm:master Jan 11, 2021
@pleerock
Copy link
Member

Thank you for contribution! 🎉

zshipleyTAG pushed a commit to Amherst-Development/typeorm that referenced this pull request Oct 7, 2022
* typeorm-0.2.30: (212 commits)
  version bump
  docs: fix javascript usage examples (typeorm#7031)
  fix: resolve migration for UpdateDateColumn without ON UPDATE clause (typeorm#7057)
  fix: Error when sorting by an embedded entity while using join and skip/take (typeorm#7082)
  fix: resolves Postgres sequence identifier length error (typeorm#7115)
  feat: closure table custom naming (typeorm#7120)
  feat: relations: Orphaned row action (typeorm#7105)
  docs: fix invalid code block in "find many options" (typeorm#7268)
  docs: Embodying the example (typeorm#7116)
  docs: document withDeleted option (typeorm#7132)
  fix: return 'null' (instead of 'undefined') on lazy relations that have no results (typeorm#7146) (typeorm#7147)
  docs: update cascade options (typeorm#7140)
  docs: add .ts to supported ormconfig formats (typeorm#7139)
  fix: improve stack traces when using persist executor (typeorm#7218)
  refactor: remove Oracle multirow insert workaround (since typeorm#6927) (typeorm#7083)
  feat: add NOWAIT and SKIP LOCKED lock support for MySQL (typeorm#7236)
  docs: update OneToMany grammar (typeorm#7252)
  feat: JavaScript file migrations output (typeorm#7253)
  docs: update Repository.ts (typeorm#7254)
  chore: update dependency cli-highlight to v2.1.10 (typeorm#7265)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants