Skip to content

Commit

Permalink
MISC: Always include stack trace in Recovery Mode (#1487)
Browse files Browse the repository at this point in the history
We are getting some more error reports coming in that don't have enough
info in them. It turns out that populating the stack trace was gated
behind the dev flag; in reality, production builds are where we need it
most. Even if it ends up being obfuscated (source maps should prevent
this), we can figure out the actual source lines with enough effort if
need be.

This also changes to using the actual stack trace, rather than the
"component" trace (the tree of JSX objects), since knowing where the
code failed is far more valuable. Also, it ensures we get the full error
details when things go wrong in savefile loading.
  • Loading branch information
d0sboots authored Jul 15, 2024
1 parent 864613c commit abe7a43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/ui/React/RecoveryRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Settings } from "../../Settings/Settings";
import { load } from "../../db";
import { Router } from "../GameRoot";
import { Page } from "../Router";
import { IErrorData, newIssueUrl } from "../../utils/ErrorHelper";
import { IErrorData, newIssueUrl, getErrorForDisplay } from "../../utils/ErrorHelper";
import { DeleteGameButton } from "./DeleteGameButton";
import { SoftResetButton } from "./SoftResetButton";

Expand Down Expand Up @@ -38,6 +38,13 @@ export function RecoveryRoot({ softReset, errorData, resetError }: IProps): Reac
}
Settings.AutosaveInterval = 0;

// The architecture around RecoveryRoot is awkward, and it can be invoked in
// a number of ways. If we are invoked via a save error, sourceError will be set
// and we won't have decoded the information into errorData.
if (errorData == null && sourceError) {
errorData = getErrorForDisplay(sourceError, undefined, Page.LoadingScreen);
}

useEffect(() => {
load()
.then((content) => {
Expand Down
18 changes: 7 additions & 11 deletions src/utils/ErrorHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface BrowserFeatures {
}

interface IErrorMetadata {
error: Error;
error: Record<string, unknown>;
errorInfo?: React.ErrorInfo;
page?: Page;

Expand All @@ -54,7 +54,7 @@ export interface IErrorData {

export const newIssueUrl = `https://github.com/bitburner-official/bitburner-src/issues/new`;

function getErrorMetadata(error: Error, errorInfo?: React.ErrorInfo, page?: Page): IErrorMetadata {
function getErrorMetadata(error: unknown, errorInfo?: React.ErrorInfo, page?: Page): IErrorMetadata {
const isElectron = navigator.userAgent.toLowerCase().includes(" electron/");
const env = process.env.NODE_ENV === "development" ? GameEnv.Development : GameEnv.Production;
const version: GameVersion = {
Expand All @@ -70,19 +70,20 @@ function getErrorMetadata(error: Error, errorInfo?: React.ErrorInfo, page?: Page
doNotTrack: navigator.doNotTrack,
indexedDb: !!window.indexedDB,
};
const errorObj = typeof error === "object" && error !== null ? (error as Record<string, unknown>) : {};
const metadata: IErrorMetadata = {
platform: isElectron ? Platform.Steam : Platform.Browser,
environment: env,
version,
features,
error,
error: errorObj,
errorInfo,
page,
};
return metadata;
}

export function getErrorForDisplay(error: Error, errorInfo?: React.ErrorInfo, page?: Page): IErrorData {
export function getErrorForDisplay(error: unknown, errorInfo?: React.ErrorInfo, page?: Page): IErrorData {
const metadata = getErrorMetadata(error, errorInfo, page);
const fileName = (metadata.error as any).fileName;
const features =
Expand Down Expand Up @@ -112,16 +113,11 @@ Please fill this information with details if relevant.
* Features: ${features}
* Source: ${fileName ?? "n/a"}
${
metadata.environment === GameEnv.Development
? `
### Stack Trace
\`\`\`
${metadata.errorInfo?.componentStack.toString().trim()}
${metadata.error.stack}
\`\`\`
`
: ""
}
### Save
\`\`\`
Copy your save here if possible
Expand Down

0 comments on commit abe7a43

Please sign in to comment.