Module version

Module version 

Source
Expand description

Shared YAML spec version validation helper. Ensures presence of integer version field and equality to expected version. Centralizes error message strings to keep parser modules consistent.

§Purpose

Single source of truth for spec version checks so all parsers emit identical error messages and evolve coherently when new versions are introduced.

§Usage

use serde_yaml::Value;
// Inside crate: use spec::version::validate_version
let v: Value = serde_yaml::from_str("version: 1").unwrap();
let ver = allora::spec::version::validate_version(&v).unwrap();
assert_eq!(ver, 1);

§Error Semantics

  • Missing field -> missing 'version'
  • Non-integer type -> 'version' must be integer
  • Unsupported value -> unsupported version (expected 1)

§Extension Strategy

For a future v2 schema, prefer adding validate_version_v2 or making this function accept an expected: u32 parameter. Keep old helper available to avoid breaking existing parsers. Example:

pub(crate) fn validate_version_expected(yaml: &Value, expected: u32) -> Result<u32> { /* ... */ }

§Design Notes

  • Returns u32 (small range, explicit cast from i64): avoids accidental negative values after validation.
  • Does not attempt coercion (e.g. strings); strict typing keeps configs clean.
  • Performs only version validation; structural validation remains in each parser to keep responsibilities localized.