validate_path
Stable function · Validation
Tier: stable · Kind: function · Topic: Validation
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
validate_path | not exported | validate_path | not exported | not 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); this is the file convenience, under a name that says it does I/O.
An unresolvable or ambiguous subsystem ref is a validation FINDING — the corpus
pins unresolved_subsystem_ref / ambiguous_subsystem_ref at
/models/<M>/subsystems/<S> with details — but Julia could only ever raise it
as an exception out of the loader, so validate(load_path(path)) never ran and the
finding was unreportable in the shape everyone else reports it (finding (f)).
load_path still throws: a document whose mount does not resolve genuinely cannot be
built, and callers that want the exception keep it. This entry point is the one
the conformance harness wants — it renders the throw as the structural error it
always was.
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"
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.
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 function.
Go
Go does not export this function.