{"record":{"id":"b6ba811cea68faff","repo":"pola-rs/polars","slug":"failed-to-open-the-schema-file-for-writing","errorCode":null,"errorMessage":"failed to open the schema file for writing","messagePattern":"failed to open the schema file for writing","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-plan/src/bin/dsl-schema.rs","lineNumber":77,"sourceCode":"            \"update-hashes\" => {\n                update_hashes(path.unwrap_or(DEFAULT_HASHES_PATH.to_owned()));\n            },\n            \"check-hashes\" => {\n                check_hashes(path.unwrap_or(DEFAULT_HASHES_PATH.to_owned()));\n            },\n            unknown => {\n                panic!(\"unknown command: `{unknown}`\");\n            },\n        }\n    }\n\n    /// Serializes the current DSL schema into a file at the given path.\n    ///\n    /// Any existing file at the path is overwritten.\n    fn generate(path: impl AsRef<Path>) {\n        let schema = DslPlan::dsl_schema();\n\n        let mut file = File::create(path).expect(\"failed to open the schema file for writing\");\n        serde_json::to_writer_pretty(&mut file, &schema).expect(\"failed to serialize the schema\");\n        writeln!(&mut file).expect(\"failed to write the last newline\");\n        file.flush().expect(\"failed to flush the schema file\");\n    }\n\n    /// Outputs the current DSL schema hashes into a file at the given path.\n    ///\n    /// Any existing file at the path is overwritten.\n    fn update_hashes(path: impl AsRef<Path>) {\n        std::fs::write(path, current_schema_hashes())\n            .expect(\"failed to write the schema into the file\");\n        eprintln!(\"the DSL schema file was updated\");\n    }\n\n    /// Checks that the current schema hashes match the schema hashes in the file.\n    fn check_hashes(path: impl AsRef<Path>) {\n        let file_hashes =\n            std::fs::read_to_string(path).expect(\"failed to read the schema hashes from the file\");","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-plan/src/bin/dsl-schema.rs#L59-L95","documentation":"`generate` calls `File::create(path)` and `.expect(...)`s the result. If the file cannot be created or opened for writing (bad path, missing parent directory, permissions, path is a directory), the process panics with this message. The error's underlying io::Error is included by expect.","triggerScenarios":"`dsl-schema generate <path>` where the path's parent directory doesn't exist, the path is an existing directory, or the process lacks write permission for that location.","commonSituations":"Typo'd output path, read-only filesystem/CI container, running without permissions in the target directory, or forgetting to create the output directory first.","solutions":["Verify the output directory exists and create it if needed (e.g. `mkdir -p dir`).","Check filesystem permissions on the target path and that it is not a directory.","Use the default path (`./dsl-schema.json`) by omitting the path argument and run from a writable directory."],"exampleFix":"// before\ndsl-schema generate ./missing-dir/schema.json\n\n// after\nmkdir -p ./missing-dir && dsl-schema generate ./missing-dir/schema.json","handlingStrategy":"validation","validationCode":"import os\npath = \"./out/schema.json\"\nos.makedirs(os.path.dirname(path) or \".\", exist_ok=True)\nif os.path.isdir(path):\n    raise ValueError(f\"{path} is a directory\")\nif not os.access(os.path.dirname(path) or \".\", os.W_OK):\n    raise PermissionError(f\"cannot write to {path}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the output directory before generating.","Confirm the target isn't an existing directory and is writable.","In CI, verify the workspace is not mounted read-only."],"tags":["io","file-write","panic"],"backgroundTag":"file-open-failed","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}