| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b1cbe57 commit 7fbfc6d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + --- | ||
| 2 | + '@ai-sdk/provider-utils': patch | ||
| 3 | + --- | ||
| 4 | + | ||
| 5 | + Preserve streamed download size-limit errors when response cancellation fails. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -121,6 +121,42 @@ describe('readResponseWithSizeLimit', () => { | |||
| 121 | 121 | }); | |
| 122 | 122 | }); | |
| 123 | 123 | ||
| 124 | + it('should preserve streamed size-limit errors when cancellation fails', async () => { | ||
| 125 | + const cancelError = new Error('cancel failed'); | ||
| 126 | + let cancelled = false; | ||
| 127 | + const body = new ReadableStream<Uint8Array>({ | ||
| 128 | + start(controller) { | ||
| 129 | + controller.enqueue(new Uint8Array([1, 2])); | ||
| 130 | + }, | ||
| 131 | + cancel() { | ||
| 132 | + cancelled = true; | ||
| 133 | + return Promise.reject(cancelError); | ||
| 134 | + }, | ||
| 135 | + }); | ||
| 136 | + const response = { | ||
| 137 | + headers: new Headers(), | ||
| 138 | + body, | ||
| 139 | + } as unknown as Response; | ||
| 140 | + | ||
| 141 | + await expect( | ||
| 142 | + readResponseWithSizeLimit({ | ||
| 143 | + response, | ||
| 144 | + url: 'http://example.com/streaming', | ||
| 145 | + maxBytes: 1, | ||
| 146 | + }), | ||
| 147 | + ).rejects.toSatisfy((error: unknown) => { | ||
| 148 | + expect(error).not.toBe(cancelError); | ||
| 149 | + expect(DownloadError.isInstance(error)).toBe(true); | ||
| 150 | + expect((error as DownloadError).message).toBe( | ||
| 151 | + 'Download of http://example.com/streaming exceeded maximum size of 1 bytes.', | ||
| 152 | + ); | ||
| 153 | + return true; | ||
| 154 | + }); | ||
| 155 | + | ||
| 156 | + expect(cancelled).toBe(true); | ||
| 157 | + expect(body.locked).toBe(false); | ||
| 158 | + }); | ||
| 159 | + | ||
| 124 | 160 | it('should handle lying Content-Length (says small, sends large)', async () => { | |
| 125 | 161 | const largeBody = new Uint8Array(200); | |
| 126 | 162 | largeBody.fill(42); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,6 +84,8 @@ export async function readResponseWithSizeLimit({ | |||
| 84 | 84 | } finally { | |
| 85 | 85 | try { | |
| 86 | 86 | await reader.cancel(); | |
| 87 | + } catch { | ||
| 88 | + // Ignore cancel errors so the original rejection is preserved. | ||
| 87 | 89 | } finally { | |
| 88 | 90 | reader.releaseLock(); | |
| 89 | 91 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments