{"record":{"id":"1ab271d71fa6315d","repo":"seanmonstar/warp","slug":"error-reading-file","errorCode":null,"errorMessage":"error reading file ({:?}): {}","messagePattern":"error reading file \\((.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/tls.rs","lineNumber":275,"sourceCode":"    path: PathBuf,\n    file: Option<File>,\n}\n\nimpl LazyFile {\n    fn lazy_read(&mut self, buf: &mut [u8]) -> io::Result<usize> {\n        if self.file.is_none() {\n            self.file = Some(File::open(&self.path)?);\n        }\n\n        self.file.as_mut().unwrap().read(buf)\n    }\n}\n\nimpl Read for LazyFile {\n    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {\n        self.lazy_read(buf).map_err(|err| {\n            let kind = err.kind();\n            io::Error::new(\n                kind,\n                format!(\"error reading file ({:?}): {}\", self.path.display(), err),\n            )\n        })\n    }\n}\n\nimpl Transport for TlsStream {\n    fn remote_addr(&self) -> Option<SocketAddr> {\n        Some(self.remote_addr)\n    }\n}\n\nenum State {\n    Handshaking(tokio_rustls::Accept<AddrStream>),\n    Streaming(tokio_rustls::server::TlsStream<AddrStream>),\n}\n","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/seanmonstar/warp/blob/ff34d7213ed55ec342304aa7ff6ac4b351da9e66/src/tls.rs#L257-L293","documentation":"The TLS LazyFile wrapper converts any I/O error from reading the certificate/key file into an io::Error whose message embeds the file path: 'error reading file (\"path\"): <os error>'. It surfaces underlying failures like missing files or permission problems during TLS server setup.","triggerScenarios":"tls().cert_path(\"missing.pem\") or key_path pointing to a nonexistent, unreadable, or directory path — the error fires when the lazy file is first read.","commonSituations":"Wrong working directory so relative paths don't resolve; certs not deployed to the container; file permissions denied for the service user; typo'd paths in config.","solutions":["Verify the cert/key paths are absolute and the files exist (ls -l) before starting","Fix file permissions or run the service as a user that can read the certs","Correct relative paths or set the expected working directory in your deployment"],"exampleFix":"// before\ntls().cert_path(\"certs/server.pem\")\n// after\ntls().cert_path(\"/etc/ssl/certs/server.pem\") // absolute, verified path","handlingStrategy":"validation","validationCode":"for p in [&cert_path, &key_path] {\n    assert!(std::path::Path::new(p).is_file(), \"TLS file missing/unreadable: {}\", p);\n}","typeGuard":"fn readable_file(p: &str) -> Option<std::path::PathBuf> {\n    let path = std::path::PathBuf::from(p);\n    std::fs::File::open(&path).ok().map(|_| path)\n}","tryCatchPattern":"// LazyFile::read yields io::Error; match on kind()\nmatch std::fs::read(cert_path) {\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => eprintln!(\"cert missing: {}\", cert_path),\n    Err(e) => eprintln!(\"tls read failed: {}\", e),\n    Ok(_) => {},\n}","preventionTips":["Use absolute paths for cert/key files","Check file existence and permissions at service startup","Mount certs correctly in containers and run as a user with read access"],"tags":["tls","file-io","certificates"],"backgroundTag":"file-read-failed","analyzedSha":"ff34d7213ed55ec342304aa7ff6ac4b351da9e66","analyzedAt":"2026-09-09T16:57:46.316Z","contentChangedAt":"2026-09-09T16:57:46.316Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}