{"record":{"id":"d3f089875e6e4426","repo":"FuelLabs/fuels-rs","slug":"the-end-of-the-anchor-appears-before-the-beginning","errorCode":null,"errorMessage":"The end of the anchor appears before the beginning. End anchor: {end:?}. Begin anchor: {begin:?}","messagePattern":"The end of the anchor appears before the beginning\\. End anchor: (.+?)\\. Begin anchor: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"scripts/check-docs/src/lib.rs","lineNumber":153,"sourceCode":"        .collect::<Vec<_>>();\n\n    let start_only = pairs.into_iter().map(|(begin, _)| begin).collect();\n\n    (start_only, chain!(errors, additional_errors).collect())\n}\n\npub fn filter_unused_ends<'a>(ends: &'a [Anchor], pairs: &[(Anchor, Anchor)]) -> Vec<&'a Anchor> {\n    ends.iter()\n        .filter(|end| {\n            let end_used_in_pairs = pairs.iter().any(|(_, used_end)| *end == used_end);\n            !end_used_in_pairs\n        })\n        .collect()\n}\n\npub fn check_validity_of_anchor_pair(begin: &Anchor, end: &Anchor) -> Option<anyhow::Error> {\n    if begin.line_no > end.line_no {\n        Some(anyhow!(\n            \"The end of the anchor appears before the beginning. End anchor: {end:?}. Begin anchor: {begin:?}\"\n        ))\n    } else {\n        None\n    }\n}\n\n#[derive(Debug, Clone, Hash, Eq, PartialEq)]\npub struct Anchor {\n    pub line_no: usize,\n    pub name: String,\n    pub file: PathBuf,\n}\n\npub fn extract_starts_and_ends(\n    text_w_anchors: &str,\n) -> anyhow::Result<(Vec<Anchor>, Vec<Anchor>), Error> {\n    let apply_regex = |regex: Regex| {","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/FuelLabs/fuels-rs/blob/d9a250a51818dda64bfeb5ef7cc19cf27bdcd623/scripts/check-docs/src/lib.rs#L135-L171","documentation":"Doc-checking error (scripts/check-docs): an ANCHOR/ANCHOR_END pair with matching names exists in the same file, but the end marker's line number is smaller than the start marker's — the pair is inverted. check_validity_of_anchor_pair rejects pairs where begin.line_no > end.line_no.","triggerScenarios":"A file contains ANCHOR_END: x physically above ANCHOR: x — markers swapped during editing, or the 'begin' marker collected from a grep of the file is the lower occurrence while the end sits above it.","commonSituations":"Hand-editing examples and flipping the marker comments; automated refactors that reorder blocks; duplicate names where start/end got interleaved.","solutions":["Open the file named in the error and find both markers by line numbers given in the Anchor debug output.","Swap the two lines so ANCHOR: <name> precedes ANCHOR_END: <name>.","Re-run check-docs; if the file legitimately needs the snippet order reversed, rename one pair instead of swapping."],"exampleFix":"// before\n// ANCHOR_END: snippet\nfn b() {}\n// ANCHOR: snippet\nfn a() {}\n// after\n// ANCHOR: snippet\nfn a() {}\n// ANCHOR_END: snippet\nfn b() {}","handlingStrategy":"validation","validationCode":"let lines: Vec<&str> = src.lines().collect();\nlet pos = |m: &str| lines.iter().position(|l| l.contains(m));\nif let (Some(b), Some(e)) = (pos(\"ANCHOR: n\"), pos(\"ANCHOR_END: n\")) {\n    assert!(b < e, \"ANCHOR_END appears before ANCHOR\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never reorder marker comments when reordering code blocks — move the code with its markers.","Watch for this after automated sorts/formats of example files."],"tags":["docs","check-docs","anchors","ordering"],"backgroundTag":null,"analyzedSha":"d9a250a51818dda64bfeb5ef7cc19cf27bdcd623","analyzedAt":"2026-08-16T09:49:30.618Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}