Project

EarthSciAST

The EarthSciML Abstract Syntax Tree format: schema, operators, coupling, and five language bindings.

Contents

This is the documentation for the older version v0.16.0. For the latest release, see v0.17.0.

parse_error

Stable error · Errors

Tier: stable · Kind: error · Topic: Errors

JuliaTypeScriptPythonRustGo
ParseErrorParseErrornot exportednot exportednot exported

Julia

struct ParseError <: EarthSciAST._LoadDiagnostic
ParseError(code::String, message::String, path::String, file::String, details::Dict{String, Any}, original_error::Union{Nothing, Exception})
ParseError(code, message, path, file, details, original_error)
ParseError(message::AbstractString; ...)
ParseError(message::AbstractString, original_error; code, path, file, details)
ParseError <: EarthSciASTError

A document that cannot be read: malformed JSON, a value the typed coercion cannot accept, or a construct refused by name at the wire boundary (removed_op, faq_version_too_old, ic_in_reaction_system). An ordinary parse failure has an empty code; a refusal that is also a pinned finding carries its code and path, which load_failure_structural_error renders. After the common fields (see _LoadDiagnostic) comes original_error, the underlying exception, if any.

ParseError(message, original_error = nothing; code = "", path = "", file = "", details = Dict())

Source

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

From docs/api/examples/julia/documents.jl

TypeScript

class ParseError extends EsmDiagnosticError
new ParseError(message: string, originalError?: Error, code?: string): ParseError

Parse error - thrown when JSON parsing fails, or when the wire boundary refuses a document before schema validation. code defaults to parse_error; a removed op or field carries removed_op.

Source

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)

From docs/api/examples/typescript/validate.ts

Python

Python does not export this error.

Rust

Rust does not export this error.

Go

Go does not export this error.