{"record":{"id":"30512712c6e13b37","repo":"sinelaw/fresh","slug":"could-not-read-script","errorCode":null,"errorMessage":"could not read script '{}': {}","messagePattern":"could not read script '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-editor/src/main.rs","lineNumber":4682,"sourceCode":"        }\n        std::process::exit(1);\n    }\n\n    println!(\"ok\");\n    Ok(())\n}\n\n/// Read a script from a file argument, or stdin when absent or `-`.\nfn read_script_source(from: &[&str]) -> AnyhowResult<String> {\n    use std::io::Read;\n    match from.first().copied() {\n        None | Some(\"-\") => {\n            let mut buf = String::new();\n            std::io::stdin().read_to_string(&mut buf)?;\n            Ok(buf)\n        }\n        Some(path) => std::fs::read_to_string(path)\n            .map_err(|e| anyhow::anyhow!(\"could not read script '{}': {}\", path, e)),\n    }\n}\n\n/// Attach to an existing daemon, starting one if needed\nfn run_attach_command(args: &Args) -> AnyhowResult<()> {\n    run_attach(\n        args.session_name.as_deref(),\n        &args.files,\n        args.locale.as_deref(),\n        args.config.as_deref(),\n    )\n}\n\n/// `locale` and `config` are the client's own `--locale` and `--config`,\n/// forwarded to a daemon we *start* here so those flags survive the hop\n/// into the process that actually renders the UI and reads the config.\n/// Attaching to an already-running daemon leaves both alone: it is someone\n/// else's session, already serving other terminals, the same way an","sourceCodeStart":4664,"sourceCodeEnd":4700,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor/src/main.rs#L4664-L4700","documentation":"Raised while reading a script for a CLI subcommand: stdin (\"-\")/no-arg reads stdin, but an explicit path goes through `std::fs::read_to_string`, and any I/O failure is wrapped as `could not read script '{}': {}` with the OS error appended. The wrapper tells you which path failed and why (missing, permission, not a file, invalid UTF-8).","triggerScenarios":"Passing a script file path to the script-taking subcommand when the file cannot be read: nonexistent path, no read permission, it's a directory, or it contains invalid UTF-8.","commonSituations":"Typo in the script path; relative path resolved from the wrong working directory; script written with a non-UTF-8 encoding; running under a user lacking read permission.","solutions":["Check the path exists and is spelled correctly (ls the exact path).","Pipe the script via stdin instead: pass '-' or omit the path and use `... < script`.","Fix file permissions (chmod/chown) or run as a user with read access.","Re-save the script as UTF-8 — read_to_string rejects non-UTF-8 bytes."],"exampleFix":"// before: failing on a possibly-missing path\nlet src = std::fs::read_to_string(path).map_err(|e| anyhow::anyhow!(\"could not read script '{}': {}\", path, e))?;\n// after: validate before reading and give a targeted message\nif !std::path::Path::new(path).is_file() {\n    anyhow::bail!(\"script '{}' does not exist or is not a file\", path);\n}\nlet src = std::fs::read_to_string(path).map_err(|e| anyhow::anyhow!(\"could not read script '{}': {}\", path, e))?;","handlingStrategy":"validation","validationCode":"fn readable_script(path: &str) -> Result<(), String> {\n    let p = std::path::Path::new(path);\n    if !p.is_file() { return Err(format!(\"'{}' is not a file\", path)); }\n    std::fs::File::open(p).map_err(|e| e.to_string())?;\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match read_script(path) {\n    Err(e) if e.to_string().starts_with(\"could not read script\") => {\n        eprintln!(\"check the path, permissions, and that the file is UTF-8\");\n    }\n    other => other?,\n}","preventionTips":["Use absolute paths for scripts to avoid cwd surprises","Save scripts as UTF-8","Stat the file before invoking the CLI","Fall back to stdin ('-' or piping) when the path is uncertain"],"tags":["io","file","cli","script"],"backgroundTag":"file-read-failed","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}