parse_error
Stable error · Errors
Tier: stable · Kind: error · Topic: Errors
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
ParseError | ParseError | not exported | not exported | not exported |
Julia
struct ParseError <: EarthSciASTError
ParseError(message::String; ...)
ParseError(message::String, original_error; code, path, details)
ParseError
Exception thrown when JSON parsing fails.
Example (load_errors)
# Text that is not JSON at all raises a ParseError...
try
load_string("{not json")
error("expected a ParseError")
catch e
@assert e isa ParseError
println(sprint(showerror, e))
end
# ...and JSON that breaks the schema raises a SchemaValidationError, whose
# `errors` field lists each failure.
try
load_string("""{"esm": "1.0.0"}""")
error("expected a SchemaValidationError")
catch e
@assert e isa SchemaValidationError
@assert !isempty(e.errors)
println(sprint(showerror, e))
end
TypeScript
class ParseError extends EsmDiagnosticError
new ParseError(message: string, originalError?: Error): ParseError
Parse error - thrown when JSON parsing fails
Example (validate)
// A good document validates cleanly.
const good = validate(loadPath(fixture('decay.esm')))
assert.equal(good.is_valid, true)
assert.deepEqual(good.structural_errors, [])
// `validate` reports problems in its result; it does not throw. invalid.esm
// uses a variable `k` that its model never declares.
const bad = validateText(readFileSync(fixture('invalid.esm'), 'utf8'))
assert.equal(bad.is_valid, false)
assert.equal(bad.schema_errors.length, 0)
const [err] = bad.structural_errors
assert.equal(err.code, 'undefined_variable')
assert.equal(err.path, '/models/Broken/equations/0/rhs')
assert.match(err.message, /Variable "k" referenced in equation is not declared/)
// Loading a structurally invalid document still succeeds. Unit warnings found
// while loading go to `console.warn` unless you collect them yourself.
const warnings: UnitWarning[] = []
const broken = loadPath(fixture('invalid.esm'), { onUnitWarning: (w) => warnings.push(w) })
assert.equal(validate(broken).is_valid, false)
assert.match(warnings[0].message, /Unknown variable: k/)
// Text that is not JSON at all is a `ParseError`, thrown at load time.
assert.throws(() => loadString('{ not json'), ParseError)
Python
Python does not export this error.
Rust
Rust does not export this error.
Go
Go does not export this error.