Skip to content

Commit

Permalink
Don't crash if some (but not all) Error Codes are loaded (#11291)
Browse files Browse the repository at this point in the history
Co-authored-by: Lenz Weber-Tronic <[email protected]>
  • Loading branch information
ArioA and phryneas authored Oct 16, 2023
1 parent 78c00b9 commit 2be7eaf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/heavy-camels-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix a bug that allows to only call `loadErrorMessages` without also calling `loadDevErrorMessages`.
2 changes: 1 addition & 1 deletion src/dev/loadErrorMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function loadErrorMessageHandler(...errorCodes: ErrorCodes[]) {
function handler(message: string | number, args: unknown[]) {
if (typeof message === "number") {
const definition = global[ApolloErrorMessageHandler]![message];
if (!message || !definition.message) return;
if (!message || !definition?.message) return;
message = definition.message;
}
return args.reduce<string>(
Expand Down
18 changes: 18 additions & 0 deletions src/utilities/globals/__tests__/invariantWrappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,21 @@ test("invariant.log(5, ...), with handlers", () => {
{ a: 1 }
);
});

test("base invariant(false, 6, ...), raises fallback", () => {
using _ = mockErrorMessageHandler();
expect(() => {
invariant(false, 6, "hello");
}).toThrow(
new InvariantError(
"An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#" +
encodeURIComponent(
JSON.stringify({
version: "local",
message: 6,
args: ["hello"],
})
)
)
);
});

0 comments on commit 2be7eaf

Please sign in to comment.