Skip to content

Commit dc93b1d

Browse files
committed
fix: If ReadableStream fails to read (e.g. WebKit + Big Boi Files), notify as an error.
1 parent 2181381 commit dc93b1d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/upchunk.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export type ChunkedStreamIterableOptions = {
5656
export class ChunkedStreamIterable implements AsyncIterable<Blob> {
5757
protected _chunkSize: number | undefined;
5858
protected defaultChunkSize: number;
59+
protected _error: Error | undefined;
5960
public readonly minChunkSize: number;
6061
public readonly maxChunkSize: number;
6162

@@ -86,6 +87,10 @@ export class ChunkedStreamIterable implements AsyncIterable<Blob> {
8687
return this.chunkSize * 1024;
8788
}
8889

90+
get error() {
91+
return this._error;
92+
}
93+
8994
async *[Symbol.asyncIterator](): AsyncIterator<Blob> {
9095
let chunk;
9196
const reader = this.readableStream.getReader();
@@ -129,6 +134,9 @@ export class ChunkedStreamIterable implements AsyncIterable<Blob> {
129134
}
130135
}
131136
}
137+
} catch (e) {
138+
// There are edge case errors when attempting to read() from ReadableStream reader.
139+
this._error = e;
132140
} finally {
133141
// Last chunk, if any bits remain
134142
if (chunk) {
@@ -705,6 +713,11 @@ export class UpChunk {
705713
if (chunk) {
706714
chunkUploadSuccess = await this.sendChunkWithRetries(chunk);
707715
}
716+
717+
if (this.chunkedStreamIterable.error) {
718+
this.dispatch('error', { message: `Unable to read file of size ${this.file.size} bytes. Try loading from another browser.` });
719+
chunkUploadSuccess = false;
720+
}
708721
// NOTE: Need to disambiguate "last chunk to upload" (done) vs. "successfully"
709722
// uploaded last chunk to upload" (depends on status of sendChunkWithRetries),
710723
// specifically for "pending chunk" cases for the last chunk.

0 commit comments

Comments
 (0)