{"record":{"id":"7f11b6fa8b0bdfc8","repo":"tracel-ai/burn","slug":"should-be-able-to-create-the-new-file","errorCode":null,"errorMessage":"Should be able to create the new file '{}': {}","messagePattern":"Should be able to create the new file '(.+?)': (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-train/src/logger/file.rs","lineNumber":28,"sourceCode":"    /// Create a new file logger.\n    ///\n    /// # Arguments\n    ///\n    /// * `path` - The path.\n    ///\n    /// # Returns\n    ///\n    /// The file logger.\n    pub fn new(path: impl AsRef<Path>) -> Self {\n        let path = path.as_ref();\n        let mut options = std::fs::File::options();\n        let file = options\n            .write(true)\n            .truncate(true)\n            .create(true)\n            .open(path)\n            .unwrap_or_else(|err| {\n                panic!(\n                    \"Should be able to create the new file '{}': {}\",\n                    path.display(),\n                    err\n                )\n            });\n\n        Self { file }\n    }\n}\n\nimpl<T> Logger<T> for FileLogger\nwhere\n    T: std::fmt::Display,\n{\n    fn log(&mut self, item: T) {\n        writeln!(&mut self.file, \"{item}\").expect(\"Can log an item.\");\n    }\n}","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-train/src/logger/file.rs#L10-L46","documentation":"`FileLogger::new` panics when it cannot open (create/truncate) the log file at the given path with `std::fs::File::options().write(true).truncate(true).create(true)`. The panic message includes the path and the underlying `io::Error`. Burn assumes a file logger path must be creatable at startup, so it fails fast instead of returning `Result`.","triggerScenarios":"Calling `FileLogger::new(path)` (or a learner `log`/metric-logger setup using it, e.g. via `FileMetricLogger`) when the path's parent directory does not exist, the directory is not writable, the path is an existing directory, or the filesystem denies creation (permissions, read-only mount, disk full, invalid characters).","commonSituations":"Pointing the learner's checkpoint/log directory at a path whose parent folders were never created; running training in a container as a non-root user writing to a root-owned dir; read-only NFS/CI workspace; passing a directory instead of a file path; Windows path with illegal characters.","solutions":["Create the parent directory before constructing the logger: `std::fs::create_dir_all(path.parent().unwrap())`","Check permissions on the target directory and that the process user can write there","Confirm the path is a file path, not an existing directory, and uses valid characters for the OS","Verify the filesystem/mount is writable (not read-only, disk not full)","If the path is user-supplied, wrap `FileLogger::new` in `std::panic::catch_unwind` or validate writability beforehand"],"exampleFix":"// before\nlet logger = FileLogger::new(\"/var/log/train/metrics.log\"); // parent dir missing\n// after\nstd::fs::create_dir_all(\"/var/log/train\").expect(\"create log dir\");\nlet logger = FileLogger::new(\"/var/log/train/metrics.log\");","handlingStrategy":"validation","validationCode":"fn ensure_log_path_ok(path: &std::path::Path) -> std::io::Result<()> {\n    if path.is_dir() {\n        return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, \"path is a directory\"));\n    }\n    if let Some(parent) = path.parent() {\n        if !parent.as_os_str().is_empty() {\n            std::fs::create_dir_all(parent)?;\n        }\n    }\n    // probe writability with a temp create/truncate\n    std::fs::OpenOptions::new().write(true).create(true).truncate(true).open(path)?;\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always `create_dir_all` the parent directory of log/checkpoint paths before training starts","Check directory permissions for the user the training process runs as (especially in Docker/CI)","Never pass an existing directory as the logger file path","Confirm the target filesystem is writable (not read-only, disk not full)","Proactively probe-open log files at startup, before a long training run, so failures surface early"],"tags":["io","filesystem","logging","panic"],"backgroundTag":"file-open-failed","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}