schema_validation_error
Stable error · Validation
Tier: stable · Kind: error · Topic: Validation
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
SchemaValidationError | SchemaValidationError | SchemaValidationError | not exported | not 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())
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 SchemaValidationError extends EsmDiagnosticError
new SchemaValidationError(message: string, errors: SchemaError[]): SchemaValidationError
Schema validation error - thrown when schema validation fails
Python
class SchemaValidationError(EarthSciAstError)
Exception raised when schema validation fails.
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")
Rust
Rust does not export this error.
Go
Go does not export this error.