Archmage.ParseError
The first invalid value and the first JSON value of the wrong type found while the generated code converts the parsed JSON of a config item.
Inherits: RefCounted
The generated load_json creates one, so each item, and each thread, has its own. It passes it to every from_json, which records an invalid value, such as "abc" for a duration, with fail() and returns early. Each caller then adds its own part of the path with at() or message_at(), so that load_json returns a message such as [3].respawn: invalid duration "abc".
A JSON value of the wrong type, such as "abc" for an int field, is recorded with mismatch() instead. The conversion continues with the zero value, and load_json checks mismatched once for each config entry, so the message locates the entry, not the field: [3]: expected a number, got "abc".
Properties
Section titled “Properties”failed
Section titled “failed”var failed: bool = falseWhether an invalid value was found.
message
Section titled “message”var message: String = ""What is wrong with the value, such as invalid duration "abc".
var path: String = ""Where the value is, relative to the item, such as [3].respawn.
mismatched
Section titled “mismatched”var mismatched: bool = falseWhether a JSON value of the wrong type was found.
mismatch_message
Section titled “mismatch_message”var mismatch_message: String = ""What is wrong with the type of the first such value, such as expected a number, got "abc".
Methods
Section titled “Methods”fail()
Section titled “fail()”func fail(msg: String) -> voidRecords msg unless an error is already recorded.
mismatch()
Section titled “mismatch()”func mismatch(msg: String) -> voidRecords msg as a type mismatch unless one is already recorded. It does not set failed.
func at(segment: String) -> VariantAdds segment to the front of path and returns null, so that a from_json can return e.at(".field").
message_at()
Section titled “message_at()”func message_at(segment: String) -> StringAdds segment to the front of path and returns the error message, "<path>: <message>", with message when failed is true, or with mismatch_message otherwise.
json_text()
Section titled “json_text()”static func json_text(v: Variant) -> StringReturns v, a parsed JSON value, as compact JSON for an error message. Unlike JSON.stringify(), it writes a float that is an integer without a fraction, as in the config files: [5,1], not [5.0,1.0].
report()
Section titled “report()”static func report(e: Archmage.ParseError, msg: String) -> voidRecords msg in e, or reports it with push_error() when e is null, as when user code calls a from_json directly.
report_mismatch()
Section titled “report_mismatch()”static func report_mismatch(e: Archmage.ParseError, expected: String, v: Variant, type_name: String = "") -> voidRecords in e that v, a parsed JSON value, has the wrong type, or reports it with push_error() when e is null. expected describes the expected value, such as "a number". The message is expected <expected>, got <v>, where an array or an object is described by its kind and any other value by its JSON text, such as expected a number, got "abc". When type_name is not empty, the message starts with it, such as HeroTable.Stats: expected an object, got 5.