{"record":{"id":"2e2ec12076c9b59f","repo":"rust-lang/mdBook","slug":"internal-error-expected-lookup-key-to-be-in","errorCode":null,"errorMessage":"internal error: expected `{lookup_key:?}` to be in root map (chapter path is `{html_path:?}`)","messagePattern":"internal error: expected `(.+?)` to be in root map \\(chapter path is `(.+?)`\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/mdbook-html/src/html/print.rs","lineNumber":204,"sourceCode":"                        match id_remap.get(&lookup_key) {\n                            Some(id_map) => match id_map.get(&anchor_id) {\n                                Some(new_id) => new_id.clone(),\n                                None => anchor_id,\n                            },\n                            None => {\n                                // Assume the anchor goes to some non-remapped\n                                // ID that already exists.\n                                anchor_id\n                            }\n                        }\n                    }\n                    None => match path_to_root_id.get(&lookup_key) {\n                        Some(id) => id.to_string(),\n                        None => {\n                            // This should be guaranteed that either the\n                            // chapter itself is in the map (for anchor-only\n                            // links), or the is_a_chapter check above.\n                            panic!(\n                                \"internal error: expected `{lookup_key:?}` to be in \\\n                                 root map (chapter path is `{html_path:?}`)\"\n                            );\n                        }\n                    },\n                };\n                el.insert_attr(attr, format!(\"#{id}\").into());\n            }\n        }\n    }\n}\n","sourceCodeStart":186,"sourceCodeEnd":216,"githubUrl":"https://github.com/rust-lang/mdBook/blob/dc21064fc21d955a0e1f67e65e336883c3e5260b/crates/mdbook-html/src/html/print.rs#L186-L216","documentation":"During print-page rendering, mdbook-html rewrites links (rewrite_links) and maps each link target path to its chapter's root identifier using a prebuilt path_to_root_id map. If a lookup key is missing from that map and no earlier is_a_chapter check matched, the code reaches a state it believes impossible and panics with this internal-error message. It indicates a book structure or link target the renderer did not account for, not a user-facing recoverable condition.","triggerScenarios":"Rendering the print page (print.html) via render_print_page while a document contains a link (relative path or anchor-only link) whose resolved path is absent from path_to_root_id — e.g. a link pointing at a non-chapter file in src/ or an anchor link to a chapter excluded from the map.","commonSituations":"A SUMMARY.md listing or linking to files outside the chapter hierarchy, custom HTML in markdown linking to files not registered as chapters, generated/symlinked pages in src/ that never got SUMMARY entries, or partially-built books where chapters were removed while stale links remained.","solutions":["Fix the link in the offending markdown so its target path corresponds to a chapter declared in SUMMARY.md.","Add the target file to SUMMARY.md as a chapter (or draft) so it gets an entry in the root map.","Remove or rewrite links that point to non-chapter assets; reference assets via relative paths that resolve to real chapter pages.","If reproducible with a minimal book, report it as a bug to the mdbook repository since this is an intended-impossible panic."],"exampleFix":"// before (src/intro.md)\nSee [details](details.md#section).\n\n// after — ensure details.md is a chapter in SUMMARY.md:\n// SUMMARY.md\n- [Intro](./intro.md)\n- [Details](./details.md)\n// and keep the link relative and correct:\nSee [details](./details.md#section).","handlingStrategy":"validation","validationCode":"fn check_links_are_chapters(src_dir: &Path, summary_chapters: &HashSet<PathBuf>) -> Result<()> {\n    for md in markdown_files(src_dir)? {\n        for target in extract_relative_link_targets(&md)? {\n            let resolved = md.parent().unwrap().join(&target).with_extension(\"md\");\n            if !summary_chapters.contains(&resolved) {\n                bail!(\"link target {} is not a chapter in SUMMARY.md\", resolved.display());\n            }\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"// run rendering in a worker and capture the panic\nlet result = std::panic::catch_unwind(|| render_print_page(&ctx));\nif result.is_err() {\n    eprintln!(\"print-page rendering failed: check that every link target is a chapter in SUMMARY.md\");\n}","preventionTips":["Keep every linkable page declared in SUMMARY.md.","Run a link checker (mdbook-linkcheck) on the book.","Avoid hand-written links to files not managed by the summary."],"tags":["panic","internal-error","link-rewriting","html-render"],"backgroundTag":"missing-chapter-root-map-entry","analyzedSha":"dc21064fc21d955a0e1f67e65e336883c3e5260b","analyzedAt":"2026-09-01T10:15:12.134Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}