Skip to content

fix: handle DOMException in Boom constructor - #307

Open
jpage-godaddy wants to merge 1 commit into
hapijs:masterfrom
jpage-godaddy:dom-exception-handling
Open

fix: handle DOMException in Boom constructor#307
jpage-godaddy wants to merge 1 commit into
hapijs:masterfrom
jpage-godaddy:dom-exception-handling

Conversation

@jpage-godaddy

@jpage-godaddy jpage-godaddy commented Jun 4, 2025

Copy link
Copy Markdown

DOMException instances have getters that require correct 'this' context. Hoek.clone() creates copies that lose the internal structure needed for these getters to work, causing "Value of 'this' must be of DOMException" errors. Extract message and name properties before cloning to avoid this issue.

Example stack trace error we were getting:

TypeError: Value of "this" must be of DOMException
    at throwInvalidThisError (node:internal/per_context/domexception:17:15)
    at get message [as message] (node:internal/per_context/domexception:90:7)
    at internals.initialize (/.../@hapi/boom/lib/index.js:427:14)
    at exports.boomify (/.../@hapi/boom/lib/index.js:126:26)
    at new exports.Boom (/.../@hapi/boom/lib/index.js:74:28)
    at internals.serverError (/.../@hapi/boom/lib/index.js:468:12)
    at exports.badImplementation (/.../@hapi/boom/lib/index.js:400:27)
    at ...
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ERR_INVALID_THIS'
}

DOMException instances have getters that require correct 'this' context.
Hoek.clone() creates copies that lose the internal structure needed for
these getters to work, causing "Value of 'this' must be of DOMException"
errors. Extract message and name properties before cloning to avoid this issue.
Marsup added a commit that referenced this pull request Aug 2, 2026
Marsup added a commit that referenced this pull request Aug 2, 2026
* chore: change CI target for next

* chore: add next branch to CI targets

* chore: bump lab

* Rework to be a regular class instance

* Tighten input types and make cause option explicit

* Remove decorate option

* Allow to boomify non-Error errors

* Make _apply internal

* Make isBoom a prototype property

* Make isServer property computed

* Refactor output and payload to classes

* Remove unauthorized payload.attributes

* Fix WWW-Authenticate header when empty attributes

* Refactor implementation to use helpers

* Add and use a Boom "headers" option

* Use statusError for all helpers

* Throw TypeError instead of Hoek assertion

* Remove typeof property

* Fix legacy boom object support

* Add tests for "name" property

* Explicit cause in super() call

Co-authored-by: Matthieu Sieben <matthieusieben@users.noreply.github.com>

* Assign .cause if not handled by super() call

* Fix and update typings

* Clone incoming headers

* Cleanup typings

* Narrow typings

Co-authored-by: Matthieu Sieben <matthieusieben@users.noreply.github.com>

* Revert "Remove decorate option"

This reverts commit 19e5e2a.

# Conflicts:
#	lib/index.js

* Use decorate option internally

* Allow usage on runtimes with no Error.captureStackTrace()

* Update docs

* Restore decorate option to typings

* Make reformat() apply to initial payload

* Update typescript

* Fix tests on windows filesystem

* Don't set cause when not in the options

* Allow isServer to be written to

* Fix boomify option typings

* Improve boomify typings

* Document headers option

* Require data option when Data generic is not unknown

* Remove decorate option

* Improve boomify data type support

* Improve docs

* Fix notImplemented and more setting Error cause

* Cleanup

* Ignore all non-object headers option

* Shallow copy headers and throw when bad

* Directly require escapeHeaderAttribute

* chore: convert module to ESM

* chore: add regression tests based on #307

---------

Co-authored-by: Gil Pedersen <git@gpost.dk>
Co-authored-by: Gil Pedersen <github@gpost.dk>
Co-authored-by: Matthieu Sieben <matthieusieben@users.noreply.github.com>
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.

1 participant