Skip to content

Commit 8dadc89

Browse files
authored
Make sure details are logged in errors (#4)
1 parent da81b8a commit 8dadc89

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/lib/utils/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class EError<T = unknown> extends Error {
3030
}
3131

3232
/** Convert an error into an object, recursively serializing causes as needed. */
33-
private static serialize(error: unknown): unknown {
33+
public static serialize(error: unknown): unknown {
3434
// Wrapping the recursion in this inner function to hide the recursion parameter
3535
function serializeRecurse(error: unknown, recursion: number): unknown {
3636
if (error === undefined || error === null) {

src/pages/Content.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createPortal } from "react-dom";
44
import { useTooltip } from "@lib/hooks/useTooltip";
55
import { ErrorBoundaryProvider } from "@lib/wrappers/ErrorBoundary";
66
import { clsx } from "@lib/utils/clsx";
7-
import { ENoIntegrationError, EShadowError } from "@lib/utils/error";
7+
import { EError, ENoIntegrationError, EShadowError } from "@lib/utils/error";
88
import { DevPodLogoIcon } from "@src/icons/devpod";
99
import { StrictMode } from "react";
1010
import { ButtonLink } from "@lib/components/Button";
@@ -28,19 +28,18 @@ function getDevPodUrl() {
2828
branch = integration.getBranch({ url, document });
2929
} catch (error) {
3030
if (
31-
error instanceof EIntegrationParseError &&
32-
error.data?.cause === "no match"
31+
// "no match" errors are expected when we're on the main branch
32+
!(error instanceof EIntegrationParseError) ||
33+
error.data?.cause !== "no match"
3334
) {
34-
// We're just not on any branch, that's fine. DevPod will automatically check out the default branch.
35-
} else {
3635
throw error;
3736
}
3837
}
3938

4039
const branchSuffix = branch ? `@${branch}` : "";
4140
return `https://devpod.sh/open#https://github.com/${repo}${branchSuffix}`;
4241
} catch (error) {
43-
console.error(error);
42+
console.error(EError.serialize(error));
4443
throw error;
4544
}
4645
}
@@ -131,7 +130,10 @@ function init(attempts: number = 0) {
131130
if (error instanceof ENoIntegrationError) {
132131
// Ignore, expected error when the site is not supported.
133132
} else {
134-
console.info("Initialization failed", { attempts, error });
133+
console.info("Initialization failed", {
134+
attempts,
135+
error: EError.serialize(error),
136+
});
135137
}
136138
// 10ms, 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1280ms, 2560ms, 5120ms, 10240ms, 20480ms
137139
setTimeout(() => init(attempts + 1), Math.pow(2, attempts) * 10);

0 commit comments

Comments
 (0)