mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
refactor(il2cpp): report format failures through ParseFailure (#10701)
This commit is contained in:
1 parent
cd5ea9a9fb
commit
3a29b6b8ea
12 files changed
+150
-42
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { ParseFailureError } from "../domain/parseFailure.js";
|
||||
|
||||
/** Existing selected-binary allowance also bounds its retained pointer workspace. */
|
||||
export const IL2CPP_BINARY_BYTES = 1024 * 1024 * 1024;
|
||||
|
||||
@@ -29,24 +31,59 @@ export const IL2CPP_BINARY_FAILURE_REASONS = {
|
||||
|
||||
export type Il2cppBinaryFailureReason =
|
||||
(typeof IL2CPP_BINARY_FAILURE_REASONS)[keyof typeof IL2CPP_BINARY_FAILURE_REASONS][number];
|
||||
/** A named workspace budget; the parse stopped without showing the input invalid. */
|
||||
export type Il2cppBinaryCapacityReason =
|
||||
(typeof IL2CPP_BINARY_FAILURE_REASONS.capacity)[number];
|
||||
type Il2cppBinaryFormatReason = Exclude<
|
||||
Il2cppBinaryFailureReason,
|
||||
Il2cppBinaryCapacityReason
|
||||
>;
|
||||
|
||||
/** A native image REA cannot link, either outside coverage or inconsistent with the metadata. */
|
||||
export class Il2cppBinaryFormatFailure extends Error {
|
||||
readonly kind: "unsupported" | "malformed" | "capacity";
|
||||
/** The ParseFailure format of a native image linked against IL2CPP metadata. */
|
||||
export const IL2CPP_BINARY_FORMAT = "il2cpp-binary";
|
||||
|
||||
const isUnsupported = (reason: Il2cppBinaryFormatReason) =>
|
||||
(IL2CPP_BINARY_FAILURE_REASONS.unsupported as readonly string[]).includes(
|
||||
reason,
|
||||
);
|
||||
|
||||
/**
|
||||
* A native image REA cannot link, either outside coverage or inconsistent
|
||||
* with the metadata. The stable `reason` names the IL2CPP rule; a capacity
|
||||
* reason is a ParseFailure `limit` carrying the exceeded maximum.
|
||||
*/
|
||||
export class Il2cppBinaryFormatFailure extends ParseFailureError<
|
||||
"malformed" | "unsupported" | "limit"
|
||||
> {
|
||||
constructor(reason: Il2cppBinaryFormatReason, message: string);
|
||||
constructor(
|
||||
reason: Il2cppBinaryCapacityReason,
|
||||
message: string,
|
||||
maximum: number,
|
||||
);
|
||||
constructor(
|
||||
readonly reason: Il2cppBinaryFailureReason,
|
||||
message: string,
|
||||
maximum?: number,
|
||||
) {
|
||||
super(`${reason}: ${message}`);
|
||||
const detail = `${reason}: ${message}`;
|
||||
super(
|
||||
maximum !== undefined
|
||||
? {
|
||||
kind: "limit",
|
||||
format: IL2CPP_BINARY_FORMAT,
|
||||
detail,
|
||||
limit: { name: reason, maximum },
|
||||
}
|
||||
: isUnsupported(reason as Il2cppBinaryFormatReason)
|
||||
? {
|
||||
kind: "unsupported",
|
||||
format: IL2CPP_BINARY_FORMAT,
|
||||
detail,
|
||||
undecodedContent: false,
|
||||
}
|
||||
: { kind: "malformed", format: IL2CPP_BINARY_FORMAT, detail },
|
||||
);
|
||||
this.name = "Il2cppBinaryFormatFailure";
|
||||
this.kind = (
|
||||
IL2CPP_BINARY_FAILURE_REASONS.unsupported as readonly string[]
|
||||
).includes(reason)
|
||||
? "unsupported"
|
||||
: (IL2CPP_BINARY_FAILURE_REASONS.capacity as readonly string[]).includes(
|
||||
reason,
|
||||
)
|
||||
? "capacity"
|
||||
: "malformed";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user