Project

EarthSciAST

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

Contents

validate_path

Stable function · Validation

Tier: stable · Kind: function · Topic: Validation

JuliaTypeScriptPythonRustGo
validate_pathnot exportedvalidate_pathnot exportednot exported

Julia

validate_path(path::AbstractString)
validate_path(path::AbstractString) -> ValidationResult

Validate the document at path, INCLUDING the failures that happen while loading it; validate itself takes a TYPED document in every binding (API_SPEC.md §8 item 13). A load failure is a verdict, not an exception, as in validate_text , which renders it the same way. load_path still throws, for callers that want the exception.

Source

Example (validate)

result = validate(doc)
@assert result isa ValidationResult
@assert result.is_valid

# A document that loads fine but uses a variable it never declares. Validation
# reports the problem in the result rather than throwing.
bad = validate_path(joinpath(FIXTURES, "invalid.esm"))
@assert !bad.is_valid
err = only(bad.structural_errors)
println(err.path, ": ", err.message)
@assert err.message == "Variable 'k' referenced in equation is not declared"
@assert err.path == "/models/Broken/equations/0/rhs"

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

TypeScript

TypeScript does not export this function.

Python

validate_path(path: str, *, base_path: str | None = None) -> ValidationResult

Validate the ESM document stored at path (API_SPEC.md §8 item 13).

Convenience over validate(load_path(path)) that additionally reports a LOAD failure as a ValidationResult instead of raising. base_path defaults to the file’s own directory inside load_path , so relative §4.7 mounts resolve without being told where they are.

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 function.

Go

Go does not export this function.