Skip to content

Commit

Permalink
Fix flaky decompression error code (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm authored Sep 3, 2024
1 parent 56f07b6 commit 4422dda
Showing 1 changed file with 16 additions and 21 deletions.
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),
);
});
}

0 comments on commit 4422dda

Please sign in to comment.