pub fn validate(
ctx: &Context,
req: ValidateRequest,
) -> Result<Outcome<ValidationReport>, CoreError>Expand description
Validate every recipe under req’s root.
The root is ValidateRequest::base_dir, or Context::base_path when
that is unset. Nothing else on the context is consulted.
§Errors are data
This returns Ok for a collection of entirely broken recipes: finding those
errors is the job, and they come back in the report. It returns Err only
when the walk could not happen at all. The returned Outcome also carries
every diagnostic as one flat list, so that
has_errors means what it says — the same
diagnostics as in the report, each naming its own file.
§has_errors is not the whole verdict
A broken recipe reference is not a diagnostic, so a collection whose
only fault is a reference leading nowhere has an empty
Outcome::diagnostics and has_errors() == false. Resolving references
costs a filesystem lookup each and needs a decision this function does not
make, so it is broken_references’s separate job.
A caller gating on validation — a CI exit code, an editor’s problem list — therefore wants both:
let outcome = doctor::validate(&ctx, doctor::ValidateRequest::default())?;
let ok = !outcome.has_errors() && doctor::broken_references(&outcome.value).is_empty();cook doctor validate --strict fails on either, which is why it does its
own arithmetic over the two.
§Timer quantities
The walk uses PARSER, then warns when a timer’s
quantity is text — ~{a few%minutes}, ~{overnight}, ~{½%hour} — but
not a numeric range such as ~{10-20%minutes}, which the parser reads as
text only because range values are off. The unit is not checked, so
~{1%hr} and ~{10%Minutes} are not diagnostics, and neither is a textual
ingredient quantity (@salt{to taste}). A named timer with no quantity
(~dough) stays valid. The warning does not drop the recipe, so its
references are still collected. Nothing else about a recipe changes: the
parser is the one every other command uses.
§Errors
CoreError::Searchif the root does not exist, is not a directory, or cannot be turned into a search pattern.CoreError::Ioif a file under the root turned up in the walk and could not be listed. A file that is listed and then cannot be read is not an error: it is one recipe in the report carrying one error diagnostic.