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 <: EarthSciASTError
SchemaValidationError(message::String, errors::Vector{SchemaError})
SchemaValidationError(message, errors)
SchemaValidationError
Exception thrown when schema validation fails. Contains detailed error information including paths and messages.
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.