FuelLabs/fuels-rs · error · anyhow::Error

Couldn't find a matching end anchor for {start:?}

Error message

Couldn't find a matching end anchor for {start:?}

What it means

Doc-checking error (scripts/check-docs): a start marker ANCHOR: <name> was found but no matching ANCHOR_END: <name> exists in the same file. Anchor pairing requires exactly one end marker with the same name in the same file; zero matches produce this error.

Source

Thrown at scripts/check-docs/src/lib.rs:119

    apply_regex(
        Regex::new(r"^(\S+):(\d+):\s*\{\{\s*#include\s*(\S+?)\s*(?::\s*(\S+)\s*)?\}\}")
            .expect("could not construct regex"),
    )
}

pub fn filter_valid_anchors(starts: Vec<Anchor>, ends: Vec<Anchor>) -> (Vec<Anchor>, Vec<Error>) {
    let find_anchor_end_by_name = |anchor_name: &str, file: &Path| {
        ends.iter()
            .filter(|el| el.name == *anchor_name && el.file == file)
            .collect::<Vec<_>>()
    };

    let (pairs, errors):(Vec<_>, Vec<_>) = starts.into_iter().map(|start| {
        let matches_by_name = find_anchor_end_by_name(&start.name, &start.file);

        let (begin, end) = match matches_by_name.as_slice() {
            [single_match] => Ok((start, (*single_match).clone())),
            [] => Err(anyhow!("Couldn't find a matching end anchor for {start:?}")),
            multiple_ends => Err(anyhow!("Found too many matching anchor ends for anchor: {start:?}. The matching ends are: {multiple_ends:?}")),
        }?;

        match check_validity_of_anchor_pair(&begin, &end) {
            None => Ok((begin, end)),
            Some(err) => {
                let err_msg = err.to_string();
                Err(anyhow!("{err_msg}"))
            }
        }
    }).partition_result();

    let additional_errors = filter_unused_ends(&ends, &pairs)
        .into_iter()
        .map(|unused_end| anyhow!("Missing anchor start for {unused_end:?}"))
        .collect::<Vec<_>>();

    let start_only = pairs.into_iter().map(|(begin, _)| begin).collect();

View on GitHub (pinned to d9a250a518)

Solutions

  1. In the file reported by the error, locate the ANCHOR: <name> marker.
  2. Add or fix the matching ANCHOR_END: <name> after the snippet's last line, with the identical name.
  3. Ensure start and end are in the same file; move markers if the snippet spans files.
  4. Re-run check-docs to confirm pairing.

Example fix

// before
// ANCHOR: transfer_funds
pub async fn transfer() { /* ... */ }
// ANCHOR_END: transfer
// after
// ANCHOR: transfer_funds
pub async fn transfer() { /* ... */ }
// ANCHOR_END: transfer_funds
Defensive patterns

Strategy: validation

Validate before calling

let src = fs::read_to_string(file)?;
let starts: Vec<&str> = src.lines().filter_map(|l| l.strip_prefix("// ANCHOR:")).map(str::trim).collect();
let ends: Vec<&str> = src.lines().filter_map(|l| l.strip_prefix("// ANCHOR_END:")).map(str::trim).collect();
for s in &starts {
    assert!(ends.contains(s), "missing ANCHOR_END: {s} in {file:?}");
}

Prevention

When it happens

Trigger: A source file contains ANCHOR: my_name but the corresponding ANCHOR_END: my_name is missing, misspelled, in a different file, or the start name was edited without updating the end.

Common situations: Copy-pasting an ANCHOR block and altering only the start name; deleting the end marker while trimming an example; renaming an anchor on one line only.

Related errors


AI-assisted analysis of FuelLabs/fuels-rs@d9a250a518 (2026-08-16). Data as JSON: /api/errors/5e0c7471bb51bb0b. Report an issue: GitHub.