denoland/deno · error
Failed to read from stdin
Error message
Failed to read from stdin
What it means
When linting from stdin, Deno reads all of standard input into a String via read_to_string. Any read failure — most commonly non-UTF-8 bytes in the stream — aborts with this message before linting begins.
Source
Thrown at cli/tools/lint/mod.rs:613
) -> Result<bool, AnyError> {
let start_dir = &cli_options.start_dir;
let reporter_lock = Arc::new(Mutex::new(create_reporter(
workspace_lint_options.reporter_kind,
)));
let lint_config = start_dir
.to_lint_config(FilePatterns::new_with_base(start_dir.dir_path()))?;
let deno_lint_config =
resolve_lint_config(compiler_options_resolver, start_dir.dir_url())?;
let lint_options = LintOptions::resolve(lint_config, &lint_flags)?;
let configured_rules = lint_rule_provider
.resolve_lint_rules_err_empty(lint_options.rules, Some(start_dir))?;
let mut file_path = cli_options.initial_cwd().join(STDIN_FILE_NAME);
if let Some(ext) = cli_options.ext_flag() {
file_path.set_extension(ext);
}
let mut source_code = String::new();
if stdin().read_to_string(&mut source_code).is_err() {
return Err(anyhow!("Failed to read from stdin"));
}
let linter = CliLinter::new(CliLinterOptions {
fix: false,
configured_rules,
deno_lint_config,
maybe_plugin_runner: None,
});
let r = linter.lint_file(&file_path, deno_ast::strip_bom(source_code), None);
let success =
handle_lint_result(&file_path.to_string_lossy(), r, reporter_lock.clone());
reporter_lock.lock().close(1);
Ok(success)
}
fn handle_lint_result(View on GitHub (pinned to 89f33cbef2)
Solutions
- Confirm the input is UTF-8 text (file src.ts or iconv probe)
- Convert before piping: iconv -f UTF-16 -t UTF-8 src.ts | deno lint -
- Pass file paths to deno lint instead of concatenating many files through stdin
- Note: BOMs are handled (strip_bom); only encoding/IO breakage triggers this
Example fix
# before (src.ts is UTF-16) cat src.ts | deno lint - # after iconv -f UTF-16 -t UTF-8 src.ts | deno lint -
Defensive patterns
Strategy: validation
Validate before calling
# bail on non-UTF-8 before invoking deno if ! iconv -f UTF-8 -t UTF-8 src.ts >/dev/null 2>&1; then echo "src.ts is not valid UTF-8" >&2 exit 2 fi cat src.ts | deno lint -
Prevention
- Standardize on UTF-8 in editor settings and .editorconfig
- Pipe only single known-text files to stdin lint, never concatenated lists
When it happens
Trigger: Piping binary or non-UTF-8-encoded content into `deno lint -` (e.g. cat icon.png | deno lint -), a broken/closed pipe mid-read, or a source file in UTF-16/latin-1 encoding.
Common situations: Windows-created files saved as UTF-16; accidentally concatenating a binary file into the lint stream; tooling that closes stdin early.
Related errors
- Lint watch on standard input is not supported.
- ${prefix}Linter plugin name must only contain lowercase lett
- ${prefix}Linter plugin name must start and end with a lowerc
- ${prefix}Linter plugin name must not have consequtive hyphen
- ${prefix}Linter plugin rules must be an object
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/5fc9dc75cbeb19f6.
Report an issue: GitHub.