mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 18:50:56 +02:00
UI: Show useful error messages when loading unsupported save data from newer versions (#2425)
This commit is contained in:
@@ -195,3 +195,18 @@ Copy your save here if possible
|
||||
issueUrl,
|
||||
};
|
||||
}
|
||||
|
||||
export function isSaveDataFromNewerVersions(versionSave?: string): boolean {
|
||||
if (versionSave == null) {
|
||||
return false;
|
||||
}
|
||||
// x.y and x.y.z formats are from pre-v1 versions.
|
||||
if (versionSave.includes(".")) {
|
||||
return false;
|
||||
}
|
||||
const versionNumber = Number(versionSave);
|
||||
if (!Number.isFinite(versionNumber) || versionNumber <= CONSTANTS.VersionNumber) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import { constructorsForReviver, isReviverValue } from "./JSONReviver";
|
||||
import { validateObject } from "./Validator";
|
||||
|
||||
export class JSONReviverError extends Error {
|
||||
ctor: string;
|
||||
constructor(message: string, ctor: string) {
|
||||
super(message);
|
||||
this.name = this.constructor.name;
|
||||
this.ctor = ctor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic "smart reviver" function.
|
||||
* Looks for object values with a `ctor` property and a `data` property.
|
||||
@@ -25,7 +34,7 @@ export function Reviver(_key: string, value: unknown): any {
|
||||
return value.data;
|
||||
}
|
||||
// Missing constructor with no special handling. Throw error.
|
||||
throw new Error(`Could not locate constructor named ${value.ctor}. If the save data is valid, this is a bug.`);
|
||||
throw new JSONReviverError(`Could not locate constructor named ${value.ctor}.`, value.ctor);
|
||||
}
|
||||
|
||||
const obj = ctor.fromJSON(value);
|
||||
|
||||
Reference in New Issue
Block a user