{"record":{"id":"1568a1e78be01bc1","repo":"denoland/deno","slug":"env-var-failed-to-open-for-append-e","errorCode":null,"errorMessage":"{ENV_VAR}: failed to open {} for append: {e}","messagePattern":"(.+?): failed to open (.+?) for append: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libs/core/modules/import_graph.rs","lineNumber":59,"sourceCode":"\nconst ENV_VAR: &str = \"DENO_SNAPSHOT_IMPORT_GRAPH\";\nconst STDERR_ENV_VAR: &str = \"DENO_LOG_LAZY_LOAD\";\n\nstruct Writer {\n  inner: Mutex<BufWriter<File>>,\n}\n\nfn writer() -> Option<&'static Writer> {\n  static WRITER: OnceLock<Option<Writer>> = OnceLock::new();\n  WRITER\n    .get_or_init(|| {\n      let path = std::env::var_os(ENV_VAR)?;\n      let file = OpenOptions::new()\n        .create(true)\n        .append(true)\n        .open(&path)\n        .unwrap_or_else(|e| {\n          panic!(\n            \"{ENV_VAR}: failed to open {} for append: {e}\",\n            std::path::Path::new(&path).display()\n          )\n        });\n      Some(Writer {\n        inner: Mutex::new(BufWriter::new(file)),\n      })\n    })\n    .as_ref()\n}\n\npub(crate) fn is_enabled() -> bool {\n  writer().is_some()\n}\n\nfn stderr_log_enabled() -> bool {\n  static ENABLED: OnceLock<bool> = OnceLock::new();\n  *ENABLED.get_or_init(|| {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/core/modules/import_graph.rs#L41-L77","documentation":"deno_core can append the JS module import graph as JSONL to the file named by DENO_SNAPSHOT_IMPORT_GRAPH — an opt-in instrumentation knob for snapshot/startup analysis. The first time an entry is written, the file is opened for append; if that open fails (missing parent directory, permission denied), the process panics with the env var name, the offending path, and the underlying OS error.","triggerScenarios":"Launching any Deno command with DENO_SNAPSHOT_IMPORT_GRAPH pointing at a path whose parent directory does not exist or is not writable — e.g. `DENO_SNAPSHOT_IMPORT_GRAPH=/tmp/graph/out.jsonl` before creating /tmp/graph, or a read-only location.","commonSituations":"CI scripts adding the knob with an uncreated output directory; local debugging after the output dir was cleaned; typos in the env var value.","solutions":["Create the parent directory: `mkdir -p` the dir containing the path you set","Point the env var at an existing writable directory (e.g. under /tmp)","Pre-verify with a quick `touch <path>` as the same user that runs Deno","Unset the variable if you no longer need the instrumentation"],"exampleFix":"# before\nDENO_SNAPSHOT_IMPORT_GRAPH=/nonexistent/graph.jsonl deno run app.ts\n\n# after\nmkdir -p /tmp/graph\nDENO_SNAPSHOT_IMPORT_GRAPH=/tmp/graph/graph.jsonl deno run app.ts","handlingStrategy":"validation","validationCode":"# create and probe the output file before launching deno\nif [ -n \"$DENO_SNAPSHOT_IMPORT_GRAPH\" ]; then\n  mkdir -p \"$(dirname \"$DENO_SNAPSHOT_IMPORT_GRAPH\")\"\n  : >> \"$DENO_SNAPSHOT_IMPORT_GRAPH\" || exit 1\nfi\ndeno run app.ts","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the parent directory of the graph file in the same script that sets the env var","Pre-test with `touch <path>` under the same user that runs Deno","Unset DENO_SNAPSHOT_IMPORT_GRAPH in environments that do not need the instrumentation"],"tags":["env-var","instrumentation","snapshot","deno-core","filesystem"],"backgroundTag":"env-var-file-path-unwritable","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}