mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 18:50:56 +02:00
MISC: Improve exception alert (#1709)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export function commitHash(): string {
|
||||
try {
|
||||
return __COMMIT_HASH__ ?? "DEV";
|
||||
} catch {
|
||||
return "DEV";
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
@@ -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.
|
||||
</>,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user