listFromJson static method
Reads the errorsJson array native sends across FFI/wasm. Never
throws: text that is not the expected JSON shape becomes one error
carrying that text verbatim, since a stale native library must not
crash the caller.
Implementation
static List<RmlCompileError> listFromJson(String json) {
try {
final decoded = jsonDecode(json);
if (decoded is! List) {
throw const FormatException('not a JSON array');
}
return decoded
.cast<Map<String, dynamic>>()
.map(
(error) => RmlCompileError(
line: error['line'] as int,
message: error['message'] as String,
id: (error['id'] as String?)?.isEmpty ?? true
? null
: error['id'] as String,
),
)
.toList();
} catch (_) {
return [RmlCompileError(line: 0, message: json.trim())];
}
}