mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 22:22:26 +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 { 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";
|
||||
@ -230,7 +230,7 @@ export function pushGameReady(): void {
|
||||
},
|
||||
game: {
|
||||
version: CONSTANTS.VersionString,
|
||||
hash: hash(),
|
||||
hash: commitHash(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -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";
|
||||
@ -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 = {
|
||||
|
@ -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";
|
||||
@ -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>
|
||||
}
|
||||
|
@ -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";
|
||||
@ -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
|
||||
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -9,7 +9,7 @@ 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";
|
||||
|
||||
@ -17,7 +17,7 @@ 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 {
|
||||
|
@ -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 {
|
||||
@ -16,7 +16,7 @@ enum Platform {
|
||||
|
||||
interface GameVersion {
|
||||
version: string;
|
||||
hash: string;
|
||||
commitHash: string;
|
||||
|
||||
toDisplay: () => string;
|
||||
}
|
||||
@ -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,
|
||||
|
@ -1,4 +1,4 @@
|
||||
export function hash(): string {
|
||||
export function commitHash(): string {
|
||||
try {
|
||||
return __COMMIT_HASH__ ?? "DEV";
|
||||
} 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