{"record":{"id":"572c563e59b63c49","repo":"sxyazi/yazi","slug":"no-syntax","errorCode":null,"errorMessage":"No syntax","messagePattern":"No syntax","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-core/src/highlighter.rs","lineNumber":125,"sourceCode":"\t\t\t*i += 1;\n\t\t\tif *i > self.skip + self.size.height as usize {\n\t\t\t\treturn Ok(false);\n\t\t\t} else if *i > self.skip {\n\t\t\t\tlines.push(spans.into_static_line());\n\t\t\t}\n\t\t\tself.ensure_not_cancelled()?;\n\t\t}\n\t\tOk(true)\n\t}\n\n\tfn process_hyper(\n\t\t&self,\n\t\tbuf: &[u8],\n\t\ti: &mut usize,\n\t\tlines: &mut Vec<Line>,\n\t\th: Option<&mut HighlightLines<'_>>,\n\t) -> Result<bool> {\n\t\tlet Some(h) = h else { bail!(\"No syntax\") };\n\t\tlet s = String::from_utf8_lossy(buf);\n\t\tlet line = [Self::to_line_widget(h.highlight_line(&s, self.syntaxes)?)];\n\n\t\tlet mut it = LineIter::parsed(&line, YAZI.preview.tab_size);\n\t\tif let Some(wrap) = YAZI.preview.wrap.into() {\n\t\t\tit = it.wrapped(wrap, self.size.width);\n\t\t}\n\n\t\twhile let Some((spans, _)) = it.next() {\n\t\t\t*i += 1;\n\t\t\tif *i > self.skip + self.size.height as usize {\n\t\t\t\treturn Ok(false);\n\t\t\t} else if *i > self.skip {\n\t\t\t\tlines.push(spans.into_static_line());\n\t\t\t}\n\t\t\tself.ensure_not_cancelled()?;\n\t\t}\n\t\tOk(true)","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-core/src/highlighter.rs#L107-L143","documentation":"The preview highlighter (yazi-core/src/highlighter.rs:125) processes a chunk of file bytes with syntax highlighting; highlighting requires a HighlightLines instance produced from a matched syntax. When none was provided (`h` is None), `process_hyper` bails with \"No syntax\" because it cannot render highlighted lines without one.","triggerScenarios":"Calling `highlight`/`process_hyper` for a buffer when no syntax was resolved for the file's filetype, i.e. the `Option<HighlightLines>` is None and `let Some(h) = h else` triggers.","commonSituations":"Previewing a file whose extension/name has no matching syntect syntax definition (unknown or missing file type), or syntect syntax set failing to load so no syntax could be matched for the detected language.","solutions":["Ensure the file type has a matching syntax definition; install/verify syntect syntax sets cover the extension.","In callers, skip highlighting and render plain text when no syntax is available instead of passing None into process_hyper.","Catch this error at the preview layer and fall back to unhighlighted output."],"exampleFix":"// before\nhighlighter.highlight(buf).unwrap_or_else(|_| bail!(\"preview failed\"))\n// after\nmatch highlighter.highlight(buf) {\n    Ok(lines) => lines,\n    Err(_) => render_plain(buf), // no syntax matched; show raw text\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match highlighter.highlight(buf) {\n    Ok(lines) => lines,\n    Err(_) => render_plain(buf), // fall back to unhighlighted preview\n}","preventionTips":["Ship/load a full syntect syntax set so common extensions resolve to a syntax.","Have callers treat absence of syntax as 'render plain', not as a hard failure.","Log unknown file types to extend the syntax mapping instead of hitting the error."],"tags":["syntax-highlighting","preview","syntect","fallback"],"backgroundTag":"no-syntax-highlighter-available","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}