{"record":{"id":"50473323f086c5cc","repo":"BoundaryML/baml","slug":"rendering-without-a-message-highlighter-cannot-fail-semantic","errorCode":null,"errorMessage":"rendering without a message highlighter cannot fail semantic highlighting","messagePattern":"rendering without a message highlighter cannot fail semantic highlighting","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"baml_language/crates/baml_compiler_diagnostics/src/render.rs","lineNumber":307,"sourceCode":"    diagnostic: &Diagnostic,\n    sources: &HashMap<FileId, String>,\n    file_paths: &HashMap<FileId, PathBuf>,\n    highlights: &SourceHighlights,\n    color: bool,\n    show_error_codes: bool,\n) -> String {\n    let highlighter = color.then(|| DiagnosticHighlighter::new(highlights, file_paths));\n    let handler = miette_handler(highlighter, color, diagnostic.severity);\n    render_miette_with_handler(\n        diagnostic,\n        sources,\n        file_paths,\n        &handler,\n        color,\n        show_error_codes,\n        None,\n    )\n    .expect(\"rendering without a message highlighter cannot fail semantic highlighting\")\n}\n\nfn miette_handler(\n    highlighter: Option<DiagnosticHighlighter>,\n    color: bool,\n    severity: Severity,\n) -> GraphicalReportHandler {\n    let mut theme = if color {\n        GraphicalTheme::unicode()\n    } else {\n        GraphicalTheme::unicode_nocolor()\n    };\n    if color {\n        theme.styles.highlights = annotation_styles(severity);\n    }\n    let mut handler = GraphicalReportHandler::new_themed(theme)\n        .with_links(false)\n        .with_urls(false)","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler_diagnostics/src/render.rs#L289-L325","documentation":"render_miette always passes None as the message highlighter and asserts that the render call cannot fail semantic highlighting. Since no highlighter is supplied, the miette render of a diagnostic with highlights is expected to succeed; any Err trips this expect. It documents that the no-highlighter rendering path is infallible with respect to semantic highlighting.","triggerScenarios":"Calling render_miette (via render_diagnostic) only panics if the underlying miette render with highlighter=None returns Err — an unexpected internal condition, not a user input problem.","commonSituations":"Seen only when modifying the crate: e.g. wiring a highlighter into render_miette or changing miette's GraphicalReportHandler setup so highlighting can fail on normal diagnostics.","solutions":["No action needed for library users.","If encountered in a modified build, propagate the error (return Result) instead of expect, or restore the None-highlighter configuration.","Verify the diagnostic's message highlights are valid byte ranges into the message text if you construct diagnostics manually."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let rendered = std::panic::catch_unwind(|| render_miette(&diag, &sources, &cfg));\nif rendered.is_err() { /* fall back to agent-format rendering */ }","preventionTips":["Keep render_miette's highlighter argument as None as designed.","Ensure diagnostics carry highlight ranges within the message text bounds.","When changing the render pipeline, return Result instead of expect."],"tags":["rust","rendering","diagnostics","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}