{"record":{"id":"49ddbfc3e3fb520d","repo":"tursodatabase/turso","slug":"error-cannot-open","errorCode":null,"errorMessage":"Error: cannot open \"{}\" – {}","messagePattern":"Error: cannot open \"(.+?)\" – (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/app.rs","lineNumber":2084,"sourceCode":"\n    fn clone_database(&mut self, output_file: &str) -> anyhow::Result<()> {\n        use std::path::Path;\n        if Path::new(output_file).exists() {\n            anyhow::bail!(\"Refusing to overwrite existing file: {output_file}\");\n        }\n        let io: Arc<dyn turso_core::IO> = Arc::new(turso_core::PlatformIO::new()?);\n        let db = Database::open_file(io.clone(), output_file, Arc::new(SqliteDialect))?;\n        let target = db.connect()?;\n\n        let mut applier = ApplyWriter::new(&target);\n        Self::dump_database_from_conn(false, self.conn.clone(), &mut applier, StderrProgress)?;\n        applier.finish()?;\n        Ok(())\n    }\n\n    fn read_sql_file(&mut self, path: &str) -> anyhow::Result<()> {\n        let file =\n            File::open(path).map_err(|e| anyhow!(\"Error: cannot open \\\"{}\\\" – {}\", path, e))?;\n        let reader = BufReader::new(file);\n\n        let mut query_buffer = String::new();\n        let mut state = ReadState::default();\n\n        for line in reader.lines() {\n            let line = line\n                .map_err(|e| anyhow!(\"Error: file \\\"{}\\\" is not valid UTF-8 text – {}\", path, e))?;\n\n            if !query_buffer.is_empty() {\n                query_buffer.push('\\n');\n            }\n            query_buffer.push_str(&line);\n\n            state.process(&line);\n\n            if state.is_complete() {\n                self.run_query(&query_buffer);","sourceCodeStart":2066,"sourceCodeEnd":2102,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/app.rs#L2066-L2102","documentation":"Thrown by read_sql_file, the .read dot-command, when File::open on the given path fails; the OS error (No such file or directory, Permission denied, Is a directory) is appended to the message (cli/app.rs:2068). It fires before any line is read, so no script statements have executed.","triggerScenarios":"`.read missing.sql`; a relative path resolved against a different working directory; a file without read permission; a path that points at a directory.","commonSituations":"Relative paths resolved from where tursodb was launched rather than where the script lives; typos; permission-restricted mounts in containers; unquoted paths containing spaces.","solutions":["Check the exact path shown in the message exists (ls it)","Use an absolute path, or a path relative to the shell's current working directory","Fix permissions (chmod/chown) if the OS error is Permission denied","Quote paths that contain spaces"],"exampleFix":"-- before\n.read scripts/init.sql   -- ERROR: cannot open \"scripts/init.sql\"\n-- after\n.read /work/repo/scripts/init.sql","handlingStrategy":"validation","validationCode":"let p = std::path::Path::new(path);\nanyhow::ensure!(p.is_file(), \"{} is not a readable file\", p.display());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the path exists and is a file before invoking .read","Prefer absolute paths in scripts that drive the CLI","Quote paths containing spaces"],"tags":["cli","dot-command","file-io","path","rust"],"backgroundTag":"file-not-found","analyzedSha":"492c4a71cd7c2649e7df83da1471b74f4b1c7aa9","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}