Skip to content

Commit 6fa3b4c

Browse files
authored
fix(middleware-flexible-checksums): advise user on InvalidChunkSizeError (#7598)
1 parent 561b890 commit 6fa3b4c

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

packages/middleware-flexible-checksums/src/flexibleChecksumsMiddleware.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,29 @@ export const flexibleChecksumsMiddleware =
157157
}
158158
}
159159

160-
const result = await next({
161-
...args,
162-
request: {
163-
...request,
164-
headers: updatedHeaders,
165-
body: updatedBody,
166-
},
167-
});
160+
try {
161+
const result = await next({
162+
...args,
163+
request: {
164+
...request,
165+
headers: updatedHeaders,
166+
body: updatedBody,
167+
},
168+
});
168169

169-
return result;
170+
return result;
171+
} catch (e: unknown) {
172+
if (e instanceof Error && e.name === "InvalidChunkSizeError") {
173+
try {
174+
if (!e.message.endsWith(".")) {
175+
e.message += ".";
176+
}
177+
e.message +=
178+
" Set [requestStreamBufferSize=number e.g. 65_536] in client constructor to instruct AWS SDK to buffer your input stream.";
179+
} catch (ignored) {
180+
// e.g. message property unwritable.
181+
}
182+
}
183+
throw e;
184+
}
170185
};

packages/middleware-flexible-checksums/src/middleware-flexible-checksums.e2e.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ describe("S3 checksums", () => {
102102
})
103103
.catch((e) => {
104104
expect(String(e)).toContain(
105-
"InvalidChunkSizeError: Only the last chunk is allowed to have a size less than 8192 bytes"
105+
"InvalidChunkSizeError: Only the last chunk is allowed to have a size less than 8192 bytes. " +
106+
"Set [requestStreamBufferSize=number e.g. 65_536] in client constructor to instruct AWS SDK to buffer your input stream."
106107
);
107108
});
108109
expect.hasAssertions();

0 commit comments

Comments
 (0)