mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 23:53:48 +01:00
MISC: Improve exception alert (#1709)
This commit is contained in:
parent
8d1cfb2d97
commit
bc51733fbe
@ -9,7 +9,7 @@ import { GetServer } from "./Server/AllServers";
|
|||||||
import { ImportPlayerData, ElectronGameData, saveObject } from "./SaveObject";
|
import { ImportPlayerData, ElectronGameData, saveObject } from "./SaveObject";
|
||||||
import { exportScripts } from "./Terminal/commands/download";
|
import { exportScripts } from "./Terminal/commands/download";
|
||||||
import { CONSTANTS } from "./Constants";
|
import { CONSTANTS } from "./Constants";
|
||||||
import { hash } from "./hash/hash";
|
import { commitHash } from "./utils/helpers/commitHash";
|
||||||
import { resolveFilePath } from "./Paths/FilePath";
|
import { resolveFilePath } from "./Paths/FilePath";
|
||||||
import { hasScriptExtension } from "./Paths/ScriptFilePath";
|
import { hasScriptExtension } from "./Paths/ScriptFilePath";
|
||||||
import { handleGetSaveDataError } from "./Netscript/ErrorMessages";
|
import { handleGetSaveDataError } from "./Netscript/ErrorMessages";
|
||||||
@ -230,7 +230,7 @@ export function pushGameReady(): void {
|
|||||||
},
|
},
|
||||||
game: {
|
game: {
|
||||||
version: CONSTANTS.VersionString,
|
version: CONSTANTS.VersionString,
|
||||||
hash: hash(),
|
hash: commitHash(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { ThemeEvents } from "../Themes/ui/Theme";
|
|||||||
import { defaultTheme } from "../Themes/Themes";
|
import { defaultTheme } from "../Themes/Themes";
|
||||||
import { defaultStyles } from "../Themes/Styles";
|
import { defaultStyles } from "../Themes/Styles";
|
||||||
import { CONSTANTS } from "../Constants";
|
import { CONSTANTS } from "../Constants";
|
||||||
import { hash } from "../hash/hash";
|
import { commitHash } from "../utils/helpers/commitHash";
|
||||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||||
import { Terminal } from "../../src/Terminal";
|
import { Terminal } from "../../src/Terminal";
|
||||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||||
@ -116,7 +116,7 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
|||||||
|
|
||||||
getGameInfo: () => () => {
|
getGameInfo: () => () => {
|
||||||
const version = CONSTANTS.VersionString;
|
const version = CONSTANTS.VersionString;
|
||||||
const commit = hash();
|
const commit = commitHash();
|
||||||
const platform = navigator.userAgent.toLowerCase().includes(" electron/") ? "Steam" : "Browser";
|
const platform = navigator.userAgent.toLowerCase().includes(" electron/") ? "Steam" : "Browser";
|
||||||
|
|
||||||
const gameInfo = {
|
const gameInfo = {
|
||||||
|
@ -52,7 +52,7 @@ import { AugmentationName } from "@enums";
|
|||||||
|
|
||||||
import { ProgramsSeen } from "../../Programs/ui/ProgramsRoot";
|
import { ProgramsSeen } from "../../Programs/ui/ProgramsRoot";
|
||||||
import { InvitationsSeen } from "../../Faction/ui/FactionsRoot";
|
import { InvitationsSeen } from "../../Faction/ui/FactionsRoot";
|
||||||
import { hash } from "../../hash/hash";
|
import { commitHash } from "../../utils/helpers/commitHash";
|
||||||
import { Locations } from "../../Locations/Locations";
|
import { Locations } from "../../Locations/Locations";
|
||||||
import { useCycleRerender } from "../../ui/React/hooks";
|
import { useCycleRerender } from "../../ui/React/hooks";
|
||||||
import { playerHasDiscoveredGo } from "../../Go/effects/effect";
|
import { playerHasDiscoveredGo } from "../../Go/effects/effect";
|
||||||
@ -277,7 +277,7 @@ export function SidebarRoot(props: { page: Page }): React.ReactElement {
|
|||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
primary={
|
primary={
|
||||||
<Tooltip title={hash()}>
|
<Tooltip title={commitHash()}>
|
||||||
<Typography>Bitburner v{CONSTANTS.VersionString}</Typography>
|
<Typography>Bitburner v{CONSTANTS.VersionString}</Typography>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ import { unalias } from "./commands/unalias";
|
|||||||
import { vim } from "./commands/vim";
|
import { vim } from "./commands/vim";
|
||||||
import { weaken } from "./commands/weaken";
|
import { weaken } from "./commands/weaken";
|
||||||
import { wget } from "./commands/wget";
|
import { wget } from "./commands/wget";
|
||||||
import { hash } from "../hash/hash";
|
import { commitHash } from "../utils/helpers/commitHash";
|
||||||
import { apr1 } from "./commands/apr1";
|
import { apr1 } from "./commands/apr1";
|
||||||
import { changelog } from "./commands/changelog";
|
import { changelog } from "./commands/changelog";
|
||||||
import { clear } from "./commands/clear";
|
import { clear } from "./commands/clear";
|
||||||
@ -139,7 +139,7 @@ export class Terminal {
|
|||||||
commandHistoryIndex = 0;
|
commandHistoryIndex = 0;
|
||||||
|
|
||||||
outputHistory: (Output | Link | RawOutput)[] = [
|
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
|
// True if a Coding Contract prompt is opened
|
||||||
@ -613,7 +613,7 @@ export class Terminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clear(): void {
|
clear(): void {
|
||||||
this.outputHistory = [new Output(`Bitburner v${CONSTANTS.VersionString} (${hash()})`, "primary")];
|
this.outputHistory = [new Output(`Bitburner v${CONSTANTS.VersionString} (${commitHash()})`, "primary")];
|
||||||
TerminalEvents.emit();
|
TerminalEvents.emit();
|
||||||
TerminalClearEvents.emit();
|
TerminalClearEvents.emit();
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ const Engine: {
|
|||||||
try {
|
try {
|
||||||
Player.bladeburner.process();
|
Player.bladeburner.process();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
exceptionAlert("Exception caught in Bladeburner.process(): " + e);
|
exceptionAlert(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Engine.Counters.mechanicProcess = 5;
|
Engine.Counters.mechanicProcess = 5;
|
||||||
|
@ -9,7 +9,7 @@ import { GameRoot } from "./GameRoot";
|
|||||||
|
|
||||||
import { CONSTANTS } from "../Constants";
|
import { CONSTANTS } from "../Constants";
|
||||||
import { ActivateRecoveryMode } from "./React/RecoveryRoot";
|
import { ActivateRecoveryMode } from "./React/RecoveryRoot";
|
||||||
import { hash } from "../hash/hash";
|
import { commitHash } from "../utils/helpers/commitHash";
|
||||||
import { pushGameReady } from "../Electron";
|
import { pushGameReady } from "../Electron";
|
||||||
import initSwc from "@swc/wasm-web";
|
import initSwc from "@swc/wasm-web";
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ export function LoadingScreen(): React.ReactElement {
|
|||||||
const [show, setShow] = useState(false);
|
const [show, setShow] = useState(false);
|
||||||
const [loaded, setLoaded] = 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") {
|
if (process.env.NODE_ENV === "development") {
|
||||||
document.title = `[dev] Bitburner ${version}`;
|
document.title = `[dev] Bitburner ${version}`;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { Page } from "../ui/Router";
|
import type { Page } from "../ui/Router";
|
||||||
import { hash } from "../hash/hash";
|
import { commitHash } from "./helpers/commitHash";
|
||||||
import { CONSTANTS } from "../Constants";
|
import { CONSTANTS } from "../Constants";
|
||||||
|
|
||||||
enum GameEnv {
|
enum GameEnv {
|
||||||
@ -16,7 +16,7 @@ enum Platform {
|
|||||||
|
|
||||||
interface GameVersion {
|
interface GameVersion {
|
||||||
version: string;
|
version: string;
|
||||||
hash: string;
|
commitHash: string;
|
||||||
|
|
||||||
toDisplay: () => string;
|
toDisplay: () => string;
|
||||||
}
|
}
|
||||||
@ -54,13 +54,13 @@ export interface IErrorData {
|
|||||||
|
|
||||||
export const newIssueUrl = `https://github.com/bitburner-official/bitburner-src/issues/new`;
|
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 isElectron = navigator.userAgent.toLowerCase().includes(" electron/");
|
||||||
const env = process.env.NODE_ENV === "development" ? GameEnv.Development : GameEnv.Production;
|
const env = process.env.NODE_ENV === "development" ? GameEnv.Development : GameEnv.Production;
|
||||||
const version: GameVersion = {
|
const version: GameVersion = {
|
||||||
version: CONSTANTS.VersionString,
|
version: CONSTANTS.VersionString,
|
||||||
hash: hash(),
|
commitHash: commitHash(),
|
||||||
toDisplay: () => `v${CONSTANTS.VersionString} (${hash()})`,
|
toDisplay: () => `v${CONSTANTS.VersionString} (${commitHash()})`,
|
||||||
};
|
};
|
||||||
const features: BrowserFeatures = {
|
const features: BrowserFeatures = {
|
||||||
userAgent: navigator.userAgent,
|
userAgent: navigator.userAgent,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export function hash(): string {
|
export function commitHash(): string {
|
||||||
try {
|
try {
|
||||||
return __COMMIT_HASH__ ?? "DEV";
|
return __COMMIT_HASH__ ?? "DEV";
|
||||||
} catch {
|
} catch {
|
@ -1,40 +0,0 @@
|
|||||||
import { dialogBoxCreate } from "../../ui/React/DialogBox";
|
|
||||||
|
|
||||||
interface IError {
|
|
||||||
fileName?: string;
|
|
||||||
lineNumber?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const isIError = (v: unknown): v is IError => {
|
|
||||||
if (typeof v !== "object" || v == null) return false;
|
|
||||||
return Object.hasOwn(v, "fileName") && Object.hasOwn(v, "lineNumber");
|
|
||||||
};
|
|
||||||
|
|
||||||
export function exceptionAlert(e: unknown): void {
|
|
||||||
console.error(e);
|
|
||||||
let msg = "";
|
|
||||||
let file = "UNKNOWN FILE NAME";
|
|
||||||
let line = "UNKNOWN LINE NUMBER";
|
|
||||||
if (isIError(e)) {
|
|
||||||
file = e.fileName ?? file;
|
|
||||||
line = e.lineNumber?.toString() ?? line;
|
|
||||||
} else {
|
|
||||||
msg = String(e);
|
|
||||||
}
|
|
||||||
dialogBoxCreate(
|
|
||||||
"Caught an exception: " +
|
|
||||||
msg +
|
|
||||||
"<br><br>" +
|
|
||||||
"Filename: " +
|
|
||||||
file +
|
|
||||||
"<br><br>" +
|
|
||||||
"Line Number: " +
|
|
||||||
line +
|
|
||||||
"<br><br>" +
|
|
||||||
"This is a bug, please report to game developer with this " +
|
|
||||||
"message as well as details about how to reproduce the bug.<br><br>" +
|
|
||||||
"If you want to be safe, I suggest refreshing the game WITHOUT saving so that your " +
|
|
||||||
"save doesn't get corrupted",
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
|
28
src/utils/helpers/exceptionAlert.tsx
Normal file
28
src/utils/helpers/exceptionAlert.tsx
Normal file
@ -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.
|
||||||
|
</>,
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user