| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4bdcaf2 commit 4d62e95
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,7 +120,14 @@ function handleKnownInternalErrors(cause) { | |||
| 120 | 120 | case cause?.code === 'ERR_STREAM_PREMATURE_CLOSE': { | |
| 121 | 121 | return new AbortError(undefined, { cause }); | |
| 122 | 122 | } | |
| 123 | - case ZLIB_FAILURES.has(cause?.code): { | ||
| 123 | + case ZLIB_FAILURES.has(cause?.code): | ||
| 124 | + // Brotli decoder error codes are formatted as 'ERR_' + | ||
| 125 | + // BrotliDecoderErrorString(), where the latter returns strings like | ||
| 126 | + // '_ERROR_FORMAT_...', '_ERROR_ALLOC_...', '_ERROR_UNREACHABLE', etc. | ||
| 127 | + // The resulting JS error codes all start with 'ERR__ERROR_'. | ||
| 128 | + // Falls through | ||
| 129 | + case cause?.code != null && | ||
| 130 | + StringPrototypeStartsWith(cause.code, 'ERR__ERROR_'): { | ||
| 124 | 131 | // eslint-disable-next-line no-restricted-syntax | |
| 125 | 132 | const error = new TypeError(undefined, { cause }); | |
| 126 | 133 | error.code = cause.code; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,3 +55,21 @@ for (const format of ['deflate', 'deflate-raw', 'gzip', 'brotli']) { | |||
| 55 | 55 | }); | |
| 56 | 56 | } | |
| 57 | 57 | } | |
| 58 | + | ||
| 59 | + // Verify that decompression errors (e.g. corrupt data) are surfaced as | ||
| 60 | + // TypeError, not plain Error, per the Compression Streams spec. | ||
| 61 | + for (const format of ['deflate', 'deflate-raw', 'gzip', 'brotli']) { | ||
| 62 | + test(`DecompressionStream surfaces corrupt data as TypeError for ${format}`, async () => { | ||
| 63 | + const ds = new DecompressionStream(format); | ||
| 64 | + const writer = ds.writable.getWriter(); | ||
| 65 | + const reader = ds.readable.getReader(); | ||
| 66 | + | ||
| 67 | + const corruptData = new Uint8Array([0, 1, 2, 3, 4, 5]); | ||
| 68 | + | ||
| 69 | + writer.write(corruptData).catch(() => {}); | ||
| 70 | + reader.read().catch(() => {}); | ||
| 71 | + | ||
| 72 | + await assert.rejects(writer.close(), { name: 'TypeError' }); | ||
| 73 | + await assert.rejects(reader.closed, { name: 'TypeError' }); | ||
| 74 | + }); | ||
| 75 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,4 @@ | |||
| 1 | 1 | { | |
| 2 | - "decompression-bad-chunks.any.js": { | ||
| 3 | - "fail": { | ||
| 4 | - "expected": [ | ||
| 5 | - "chunk of type invalid deflate bytes should error the stream for brotli", | ||
| 6 | - "chunk of type invalid gzip bytes should error the stream for brotli" | ||
| 7 | - ] | ||
| 8 | - } | ||
| 9 | - }, | ||
| 10 | 2 | "compression-with-detach.window.js": { | |
| 11 | 3 | "requires": ["crypto"] | |
| 12 | 4 | }, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments