Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky decompression error code #1204

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions packages/connect-node/src/compression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,35 +76,30 @@ function wrapZLibErrors<T>(
readMaxBytes: number,
): Promise<T> {
return promise.catch((e) => {
const { code } = getNodeErrorProps(e);
const props = getNodeErrorProps(e);
let code = Code.Internal;
let message = "decompression failed";
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (code) {
switch (props.code) {
case "ERR_BUFFER_TOO_LARGE":
e = new ConnectError(
`message is larger than configured readMaxBytes ${readMaxBytes} after decompression`,
Code.ResourceExhausted,
);
code = Code.ResourceExhausted;
message = `message is larger than configured readMaxBytes ${readMaxBytes} after decompression`;
break;
case "Z_DATA_ERROR":
case "ERR_PADDING_2":
e = new ConnectError(
"decompression failed",
Code.InvalidArgument,
undefined,
undefined,
e,
);
code = Code.InvalidArgument;
break;
default:
e = new ConnectError(
"decompression failed",
Code.Internal,
undefined,
undefined,
e,
);
if (
props.code !== undefined &&
props.code.startsWith("ERR__ERROR_FORMAT_")
) {
code = Code.InvalidArgument;
}
break;
}
return Promise.reject(e);
return Promise.reject(
new ConnectError(message, code, undefined, undefined, e),
);
});
}