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.15.1. For the latest release, see v0.17.0.

schema_validation_error

Stable error · Validation

Tier: stable · Kind: error · Topic: Validation

JuliaTypeScriptPythonRustGo
SchemaValidationErrorSchemaValidationErrorSchemaValidationErrornot exportednot exported

Julia

struct SchemaValidationError <: EarthSciAST._LoadDiagnostic
SchemaValidationError(code::String, message::String, path::String, file::String, details::Dict{String, Any}, errors::Vector{SchemaError})
SchemaValidationError(code, message, path, file, details, errors)
SchemaValidationError(message::AbstractString, errors::AbstractVector{SchemaError}; path, file, details)
SchemaValidationError <: EarthSciASTError

A document that fails the ESM schema at load. It is a load diagnostic (see _LoadDiagnostic): the common fields code (always schema_validation_error), message (the rendered list of violations), path, file and details, then errors, one SchemaError per violation.

SchemaValidationError(message, errors; 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 SchemaValidationError extends EsmDiagnosticError
new SchemaValidationError(message: string, errors: SchemaError[]): SchemaValidationError

Schema validation error - thrown when schema validation fails

Source

Python

class SchemaValidationError(EarthSciAstError)

Exception raised when schema validation fails.

Source

Example (validate)

result = earthsci_ast.validate(doc)
assert result.is_valid
assert result.schema_errors == [] and result.structural_errors == []

# validate_path reports problems in the result; it does not raise.
bad = earthsci_ast.validate_path(FIXTURES / "invalid.esm")
assert not bad.is_valid
error = bad.structural_errors[0]
print(error.code, error.path, error.message)
assert error.code == "undefined_variable"
assert "'k'" in error.message

# Loading the same file raises, because loading validates too.
try:
    earthsci_ast.load_path(FIXTURES / "invalid.esm")
except earthsci_ast.SchemaValidationError as exc:
    assert "'k'" in str(exc)
else:
    raise AssertionError("loading invalid.esm should fail")

From docs/api/examples/python/documents.py

Rust

Rust does not export this error.

Go

Go does not export this error.