Skip to main content

validate

Function validate 

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

§Errors

  • CoreError::Search if the root does not exist, is not a directory, or cannot be turned into a search pattern.
  • CoreError::Io if 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.