{"record":{"id":"46554774524ba2dc","repo":"microsoft/edit","slug":"a-language-id-is-required-when-reading-from-stdin","errorCode":null,"errorMessage":"A language ID is required when reading from stdin","messagePattern":"A language ID is required when reading from stdin","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/lsh-bin/src/main.rs","lineNumber":131,"sourceCode":") -> anyhow::Result<()> {\n    let assembly = generator.assemble()?;\n\n    let entrypoint = if let Some(language) = language {\n        assembly.entrypoints.iter().find(|ep| ep.name.replace('_', \"-\") == language).ok_or_else(\n            || anyhow::anyhow!(\"No highlighting definition found for language {language:?}\"),\n        )?\n    } else if let Some(path) = path {\n        assembly\n            .entrypoints\n            .iter()\n            .find(|ep| {\n                ep.paths.iter().any(|pattern| {\n                    glob_match(pattern.as_bytes(), path.as_os_str().as_encoded_bytes())\n                })\n            })\n            .ok_or_else(|| anyhow::anyhow!(\"No matching highlighting definition found\"))?\n    } else {\n        bail!(\"A language ID is required when reading from stdin\");\n    };\n\n    let mut color_map = Vec::new();\n    let mut unknown_kinds = Vec::new();\n    for hk in &assembly.highlight_kinds {\n        let color = match hk.identifier {\n            \"other\" => \"\",\n\n            \"comment\" => \"\\x1b[32m\",  // Green\n            \"method\" => \"\\x1b[93m\",   // Bright Yellow\n            \"string\" => \"\\x1b[91m\",   // Bright Red\n            \"variable\" => \"\\x1b[96m\", // Bright Cyan\n\n            \"constant.language\" => \"\\x1b[94m\",    // Bright Blue\n            \"constant.numeric\" => \"\\x1b[92m\",     // Bright Green\n            \"keyword.control\" => \"\\x1b[95m\",      // Bright Magenta\n            \"keyword.other\" => \"\\x1b[94m\",        // Bright Blue\n            \"keyword.preprocessor\" => \"\\x1b[94m\", // Bright Blue","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/microsoft/edit/blob/826b4c097b6f14ba0a846dc56f2f0223a3aaf73a/crates/lsh-bin/src/main.rs#L113-L149","documentation":"run_render resolves which highlighting entrypoint to use. When rendering stdin there is no file path to glob-match against entrypoint path patterns, so a language ID is mandatory; if the --language option is absent the function bails immediately.","triggerScenarios":"Piping content to lsh via stdin without specifying a language ID, i.e. language is None and path is also None when run_render is called from run.","commonSituations":"Running `cat file.rs | lsh` instead of `cat file.rs | lsh --language rust`; editors/CI integrations invoking lsh on stdin without wiring through the language flag from their config.","solutions":["Pass the language ID when reading from stdin, e.g. `lsh --language rust` (dashes in entrypoint names map to underscores).","Alternatively render an actual file path so run_render can glob-match the path against entrypoint patterns.","In wrapper scripts, derive the language from the file extension before switching to stdin mode."],"exampleFix":"// before\ncat main.rs | lsh\n// after\ncat main.rs | lsh --language rust","handlingStrategy":"validation","validationCode":"let lang = language_arg.ok_or(\"--language is required when piping to stdin\")?;\nif input_is_stdin && lang.is_none() {\n    eprintln!(\"usage: cat file | lsh --language rust\");\n    std::process::exit(2);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make --language mandatory in any wrapper that feeds lsh via stdin.","Derive the language ID from the original file extension before switching to stdin.","Prefer passing a real file path so lsh can auto-detect via glob patterns."],"tags":["cli","stdin","missing-language"],"backgroundTag":"missing-required-flag","analyzedSha":"826b4c097b6f14ba0a846dc56f2f0223a3aaf73a","analyzedAt":"2026-09-06T13:30:05.543Z","contentChangedAt":"2026-09-06T13:30:05.543Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}