Skip to content

feat(core): wrap non-Error throws from onModuleInit and onApplicationBootstrap#16789

Open
SAY-5 wants to merge 451 commits intonestjs:v12.0.0from
SAY-5:feat/wrap-non-error-init-hooks
Open

feat(core): wrap non-Error throws from onModuleInit and onApplicationBootstrap#16789
SAY-5 wants to merge 451 commits intonestjs:v12.0.0from
SAY-5:feat/wrap-non-error-init-hooks

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 15, 2026

Per #16774, when a third-party library called from onModuleInit or onApplicationBootstrap throws a value that isn't an Error instance (e.g. a plain object), Nest bubbles it straight up to bootstrap where Node logs it as an opaque UnhandledPromiseRejection with no stack trace and no module name.

This PR wraps each per-module init/bootstrap call in try/catch. If the caught value is already an Error, re-throw as-is. Otherwise wrap it in a real Error with the offending module's name and the original value attached as cause — users now get a useful message that points straight at the failing module while keeping the upstream non-Error payload accessible.

Closes #16774

kamilmysliwiec and others added 30 commits March 10, 2026 09:40
fix(deps): update dependency mysql2 to v3.19.1
chore(deps): update dependency jest to v30.3.0
chore(deps): update dependency lint-staged to v16.3.3
…ording

docs: fix front-end wording in README
…tification

feat(microservices): add redis driver identification
…t-monorepo

chore(deps): update typescript-eslint monorepo to v8.57.0
chore(deps): update dependency @eslint/eslintrc to v3.3.5
chore(deps): update dependency @types/node to v25.4.0
Bumps [lerna](https://github.com/lerna/lerna/tree/HEAD/packages/lerna) from 9.0.5 to 9.0.6.
- [Release notes](https://github.com/lerna/lerna/releases)
- [Changelog](https://github.com/lerna/lerna/blob/main/packages/lerna/CHANGELOG.md)
- [Commits](https://github.com/lerna/lerna/commits/v9.0.6/packages/lerna)

---
updated-dependencies:
- dependency-name: lerna
  dependency-version: 9.0.6
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
fix(deps): update prisma monorepo to v7.5.0
…erna-9.0.6

chore(deps-dev): bump lerna from 9.0.5 to 9.0.6
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 25.4.0 to 25.5.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-version: 25.5.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…ackages

fix(deps): update apollo graphql packages to v2.13.2
fix(deps): update dependency file-type to v21.3.2
chore(deps): update commitlint monorepo to v20.4.4
fix(deps): update dependency mongoose to v9.3.0
Bumps [@commitlint/cli](https://github.com/conventional-changelog/commitlint/tree/HEAD/@commitlint/cli) from 20.4.4 to 20.5.0.
- [Release notes](https://github.com/conventional-changelog/commitlint/releases)
- [Changelog](https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cli/CHANGELOG.md)
- [Commits](https://github.com/conventional-changelog/commitlint/commits/v20.5.0/@commitlint/cli)

---
updated-dependencies:
- dependency-name: "@commitlint/cli"
  dependency-version: 20.5.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [lint-staged](https://github.com/lint-staged/lint-staged) from 16.3.3 to 16.4.0.
- [Release notes](https://github.com/lint-staged/lint-staged/releases)
- [Changelog](https://github.com/lint-staged/lint-staged/blob/main/CHANGELOG.md)
- [Commits](lint-staged/lint-staged@v16.3.3...v16.4.0)

---
updated-dependencies:
- dependency-name: lint-staged
  dependency-version: 16.4.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
fix(deps): update dependency mysql2 to v3.20.0
…int-staged-16.4.0

chore(deps-dev): bump lint-staged from 16.3.3 to 16.4.0
…ommitlint/cli-20.5.0

chore(deps-dev): bump @commitlint/cli from 20.4.4 to 20.5.0
Bumps [lerna](https://github.com/lerna/lerna/tree/HEAD/packages/lerna) from 9.0.6 to 9.0.7.
- [Release notes](https://github.com/lerna/lerna/releases)
- [Changelog](https://github.com/lerna/lerna/blob/main/packages/lerna/CHANGELOG.md)
- [Commits](https://github.com/lerna/lerna/commits/v9.0.7/packages/lerna)

---
updated-dependencies:
- dependency-name: lerna
  dependency-version: 9.0.7
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
dependabot bot and others added 25 commits April 13, 2026 00:54
Bumps [globals](https://github.com/sindresorhus/globals) from 17.4.0 to 17.5.0.
- [Release notes](https://github.com/sindresorhus/globals/releases)
- [Commits](sindresorhus/globals@v17.4.0...v17.5.0)

---
updated-dependencies:
- dependency-name: globals
  dependency-version: 17.5.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
fix(deps): update dependency dotenv to v17.4.2
chore(deps): update dependency webpack to v5.106.1
chore(deps): update dependency @types/node to v25.6.0
chore(deps): update dependency sinon to v21.1.2
…s-morph-28.0.0

chore(deps-dev): bump ts-morph from 27.0.2 to 28.0.0
…lobals-17.5.0

chore(deps-dev): bump globals from 17.4.0 to 17.5.0
fix(deps): update dependency ts-morph to v28
chore(deps): update dependency globals to v17.5.0
fix(deps): update nest monorepo to v11.1.19
Bumps [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/typescript-eslint) from 8.58.1 to 8.58.2.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/typescript-eslint/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.58.2/packages/typescript-eslint)

---
updated-dependencies:
- dependency-name: typescript-eslint
  dependency-version: 8.58.2
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…ypescript-eslint-8.58.2

chore(deps-dev): bump typescript-eslint from 8.58.1 to 8.58.2
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.11 to 1.16.0.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](follow-redirects/follow-redirects@v1.15.11...v1.16.0)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-version: 1.16.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 8.58.1 to 8.58.2.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.58.2/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-version: 8.58.2
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…ypescript-eslint/eslint-plugin-8.58.2

chore(deps-dev): bump @typescript-eslint/eslint-plugin from 8.58.1 to 8.58.2
…ollow-redirects-1.16.0

chore(deps-dev): bump follow-redirects from 1.15.11 to 1.16.0
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 8.58.1 to 8.58.2.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.58.2/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-version: 8.58.2
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…ypescript-eslint/parser-8.58.2

chore(deps-dev): bump @typescript-eslint/parser from 8.58.1 to 8.58.2
The falsy guard `if (!message.id)` in `writeMessage` treats `id: 0` as absent, causing auto-increment to overwrite a valid explicit ID.
The same pattern in `_transform` drops `id: 0` from the serialized SSE frame entirely. Both violate the W3C SSE spec, which permits 0 as a valid event ID used for client reconnection via Last-Event-ID.

Replace both falsy checks with strict null/undefined checks so only truly absent IDs trigger auto-generation.
…y-id

fix(core): use strict null check for SSE message id
…Bootstrap

Per nestjs#16774, when a third-party library called from `onModuleInit` or
`onApplicationBootstrap` throws a value that isn't an `Error`
instance (e.g. a plain object), Nest bubbles it straight up to
`bootstrap` where Node logs it as an opaque
`UnhandledPromiseRejection` with no stack trace and no module name.

Wrap each per-module init/bootstrap call in try/catch. If the caught
value is already an Error, re-throw as-is. Otherwise wrap it in a
real Error with the offending module's name and the original value
attached as `cause` — users now get a useful message that points
straight at the failing module while keeping the upstream
non-Error payload accessible.

Closes nestjs#16774
@kamilmysliwiec
Copy link
Copy Markdown
Member

Could you rebase to v12.0.0?

@kamilmysliwiec kamilmysliwiec changed the base branch from master to v12.0.0 April 16, 2026 08:18
@kamilmysliwiec kamilmysliwiec added this to the 12.0.0 milestone Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track non-Error thrown in init hooks

9 participants