Skip to content

Commit

Permalink
MISC: Improve exception alert (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg authored Oct 22, 2024
1 parent 8d1cfb2 commit bc51733
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/Electron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GetServer } from "./Server/AllServers";
import { ImportPlayerData, ElectronGameData, saveObject } from "./SaveObject";
import { exportScripts } from "./Terminal/commands/download";
import { CONSTANTS } from "./Constants";
import { hash } from "./hash/hash";
import { commitHash } from "./utils/helpers/commitHash";
import { resolveFilePath } from "./Paths/FilePath";
import { hasScriptExtension } from "./Paths/ScriptFilePath";
import { handleGetSaveDataError } from "./Netscript/ErrorMessages";
Expand Down Expand Up @@ -230,7 +230,7 @@ export function pushGameReady(): void {
},
game: {
version: CONSTANTS.VersionString,
hash: hash(),
hash: commitHash(),
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/NetscriptFunctions/UserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ThemeEvents } from "../Themes/ui/Theme";
import { defaultTheme } from "../Themes/Themes";
import { defaultStyles } from "../Themes/Styles";
import { CONSTANTS } from "../Constants";
import { hash } from "../hash/hash";
import { commitHash } from "../utils/helpers/commitHash";
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { Terminal } from "../../src/Terminal";
import { helpers } from "../Netscript/NetscriptHelpers";
Expand Down Expand Up @@ -116,7 +116,7 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {

getGameInfo: () => () => {
const version = CONSTANTS.VersionString;
const commit = hash();
const commit = commitHash();
const platform = navigator.userAgent.toLowerCase().includes(" electron/") ? "Steam" : "Browser";

const gameInfo = {
Expand Down
4 changes: 2 additions & 2 deletions src/Sidebar/ui/SidebarRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { AugmentationName } from "@enums";

import { ProgramsSeen } from "../../Programs/ui/ProgramsRoot";
import { InvitationsSeen } from "../../Faction/ui/FactionsRoot";
import { hash } from "../../hash/hash";
import { commitHash } from "../../utils/helpers/commitHash";
import { Locations } from "../../Locations/Locations";
import { useCycleRerender } from "../../ui/React/hooks";
import { playerHasDiscoveredGo } from "../../Go/effects/effect";
Expand Down Expand Up @@ -277,7 +277,7 @@ export function SidebarRoot(props: { page: Page }): React.ReactElement {
</ListItemIcon>
<ListItemText
primary={
<Tooltip title={hash()}>
<Tooltip title={commitHash()}>
<Typography>Bitburner v{CONSTANTS.VersionString}</Typography>
</Tooltip>
}
Expand Down
6 changes: 3 additions & 3 deletions src/Terminal/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import { unalias } from "./commands/unalias";
import { vim } from "./commands/vim";
import { weaken } from "./commands/weaken";
import { wget } from "./commands/wget";
import { hash } from "../hash/hash";
import { commitHash } from "../utils/helpers/commitHash";
import { apr1 } from "./commands/apr1";
import { changelog } from "./commands/changelog";
import { clear } from "./commands/clear";
Expand Down Expand Up @@ -139,7 +139,7 @@ export class Terminal {
commandHistoryIndex = 0;

outputHistory: (Output | Link | RawOutput)[] = [
new Output(`Bitburner v${CONSTANTS.VersionString} (${hash()})`, "primary"),
new Output(`Bitburner v${CONSTANTS.VersionString} (${commitHash()})`, "primary"),
];

// True if a Coding Contract prompt is opened
Expand Down Expand Up @@ -613,7 +613,7 @@ export class Terminal {
}

clear(): void {
this.outputHistory = [new Output(`Bitburner v${CONSTANTS.VersionString} (${hash()})`, "primary")];
this.outputHistory = [new Output(`Bitburner v${CONSTANTS.VersionString} (${commitHash()})`, "primary")];
TerminalEvents.emit();
TerminalClearEvents.emit();
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ const Engine: {
try {
Player.bladeburner.process();
} catch (e) {
exceptionAlert("Exception caught in Bladeburner.process(): " + e);
exceptionAlert(e);
}
}
Engine.Counters.mechanicProcess = 5;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/LoadingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { GameRoot } from "./GameRoot";

import { CONSTANTS } from "../Constants";
import { ActivateRecoveryMode } from "./React/RecoveryRoot";
import { hash } from "../hash/hash";
import { commitHash } from "../utils/helpers/commitHash";
import { pushGameReady } from "../Electron";
import initSwc from "@swc/wasm-web";

export function LoadingScreen(): React.ReactElement {
const [show, setShow] = useState(false);
const [loaded, setLoaded] = useState(false);

const version = `v${CONSTANTS.VersionString} (${hash()})`;
const version = `v${CONSTANTS.VersionString} (${commitHash()})`;
if (process.env.NODE_ENV === "development") {
document.title = `[dev] Bitburner ${version}`;
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/utils/ErrorHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { Page } from "../ui/Router";
import { hash } from "../hash/hash";
import type { Page } from "../ui/Router";
import { commitHash } from "./helpers/commitHash";
import { CONSTANTS } from "../Constants";

enum GameEnv {
Expand All @@ -16,7 +16,7 @@ enum Platform {

interface GameVersion {
version: string;
hash: string;
commitHash: string;

toDisplay: () => string;
}
Expand Down Expand Up @@ -54,13 +54,13 @@ export interface IErrorData {

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

function getErrorMetadata(error: unknown, errorInfo?: React.ErrorInfo, page?: Page): IErrorMetadata {
export 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 = {
version: CONSTANTS.VersionString,
hash: hash(),
toDisplay: () => `v${CONSTANTS.VersionString} (${hash()})`,
commitHash: commitHash(),
toDisplay: () => `v${CONSTANTS.VersionString} (${commitHash()})`,
};
const features: BrowserFeatures = {
userAgent: navigator.userAgent,
Expand Down
2 changes: 1 addition & 1 deletion src/hash/hash.ts → src/utils/helpers/commitHash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function hash(): string {
export function commitHash(): string {
try {
return __COMMIT_HASH__ ?? "DEV";
} catch {
Expand Down
40 changes: 0 additions & 40 deletions src/utils/helpers/exceptionAlert.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/utils/helpers/exceptionAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";
import { dialogBoxCreate } from "../../ui/React/DialogBox";
import Typography from "@mui/material/Typography";
import { getErrorMetadata } from "../ErrorHelper";

export function exceptionAlert(e: unknown): void {
console.error(e);
const errorMetadata = getErrorMetadata(e);

dialogBoxCreate(
<>
Caught an exception: {String(e)}
<br />
<br />
{e instanceof Error && (
<Typography component="div" style={{ whiteSpace: "pre-wrap" }}>
Stack: {e.stack?.toString()}
</Typography>
)}
Commit: {errorMetadata.version.commitHash}
<br />
UserAgent: {navigator.userAgent}
<br />
<br />
This is a bug. Please contact developers.
</>,
);
}

0 comments on commit bc51733

Please sign in to comment.