UI: Show useful error messages when loading unsupported save data from newer versions (#2425)

This commit is contained in:
catloversg
2025-12-19 05:51:48 +07:00
committed by GitHub
parent be7bb0ad7c
commit bd2af9392f
4 changed files with 68 additions and 2 deletions
+15
View File
@@ -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;
}
+10 -1
View File
@@ -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);