This commit is contained in:
Olivier Gagnon 2022-07-14 21:54:49 -04:00
parent a0994a088c
commit c9432e4cd7
3 changed files with 14 additions and 10 deletions

@ -10,7 +10,7 @@ import { Factions } from "../Faction/Factions";
import { dialogBoxCreate } from "../ui/React/DialogBox";
import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
import { exceptionAlert } from "../utils/helpers/exceptionAlert";
import { exceptionAlert, isIError } from "../utils/helpers/exceptionAlert";
import { getRandomInt } from "../utils/helpers/getRandomInt";
import { GangMemberUpgrade } from "./GangMemberUpgrade";
@ -99,7 +99,7 @@ export class Gang implements IGang {
this.processExperienceGains(cycles);
this.processTerritoryAndPowerGains(cycles);
this.storedCycles -= cycles;
} catch (e: any) {
} catch (e: unknown) {
console.error(`Exception caught when processing Gang: ${e}`);
}
}
@ -358,7 +358,7 @@ export class Gang implements IGang {
workerScript.log("gang.ascendMember", () => `Ascended Gang member ${member.name}`);
}
return res;
} catch (e: any) {
} catch (e: unknown) {
if (workerScript == null) {
exceptionAlert(e);
}

@ -5,10 +5,10 @@
* - Adds brackets around the array
* - Adds quotation marks around strings
*/
export function arrayToString<T>(a: T[]): string {
const vals: any[] = [];
export function arrayToString(a: unknown[]): string {
const vals: unknown[] = [];
for (let i = 0; i < a.length; ++i) {
let elem: any = a[i];
let elem: unknown = a[i];
if (Array.isArray(elem)) {
elem = arrayToString(elem);
} else if (typeof elem === "string") {

@ -5,17 +5,21 @@ interface IError {
lineNumber?: number;
}
export function exceptionAlert(e: IError | string): void {
export const isIError = (v: unknown): v is IError => {
if (typeof v !== "object" || v == null) return false;
return v.hasOwnProperty("fileName") && v.hasOwnProperty("lineNumber");
};
export function exceptionAlert(e: unknown): void {
console.error(e);
let msg = "";
let file = "UNKNOWN FILE NAME";
let line = "UNKNOWN LINE NUMBER";
const isError = (e: IError | string): e is IError => e.hasOwnProperty("fileName");
if (isError(e)) {
if (isIError(e)) {
file = e.fileName ?? file;
line = e.lineNumber?.toString() ?? line;
} else {
msg = e;
msg = String(e);
}
dialogBoxCreate(
"Caught an exception: " +