fix: throw spec-correct DOMException types in WebCrypto error paths#1018
Merged
Conversation
- getRandomValues: throw QuotaExceededError (with quota/requested) on byteLength > 65536, and TypeMismatchError on non-integer TypedArray views (Float32/Float64/DataView), per WebCrypto §getRandomValues - subtle.exportKey: throw InvalidAccessError (DOMException) on non-extractable keys instead of a plain Error - lazyDOMException: use globalThis.DOMException when available; otherwise an Error subclass with .name and .code set so consumers branching on `err.name === 'InvalidAccessError'` see the spec-correct value - Add QuotaExceededError class with quota/requested fields per WebIDL Closes #998
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
🤖 End-to-End Test Results - AndroidStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot automatically captured from End-to-End tests and will expire in 30 days This comment is automatically updated on each test run. |
Contributor
🤖 End-to-End Test Results - iOSStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot automatically captured from End-to-End tests and will expire in 30 days This comment is automatically updated on each test run. |
Spec-correct DOMException errors carry the type identifier ('DataError',
'NotSupportedError', etc.) on `err.name` rather than embedded in the
message. The old `[Name]: message` formatting was non-standard. Update
the helper to look in either field so the existing tests that pass a
type-name as the expected snippet keep working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Closes #998. Aligns three WebCrypto error paths with the Web IDL spec so applications that catch by
err.name(e.g.InvalidAccessError,QuotaExceededError,TypeMismatchError) handle them correctly instead of seeing a genericError.crypto.getRandomValuesQuotaExceededErrorwithquota: 65536,requested: byteLength(was plainError)TypeMismatchError(previously silently corrupted viarandomFillSync)subtle.exportKeyon non-extractable key →InvalidAccessError(was plainError)lazyDOMExceptionhelper now usesglobalThis.DOMExceptionwhen available, otherwise anErrorsubclass with.nameand.codeset per the spec table — Hermes does not implementDOMException, so the fallback is what RN apps will see.QuotaExceededErrorclass exportingquota/requestedfields per WebIDL.Test plan
randomsuite — new tests verifygetRandomValuesthrowsQuotaExceededError(withquota/requested) on > 65536 bytesrandomsuite — new tests verifygetRandomValuesthrowsTypeMismatchErroronFloat32Array,Float64Array,DataViewsubtle.importKey/exportKeysuite — new test verifiesexportKeyof a non-extractable AES-GCM key throwsInvalidAccessErrorrandomFillSynctests (Node API) still accept Float/DataView — unchanged