{"record":{"id":"b201c09250bffbe2","repo":"projectdiscovery/nuclei","slug":"failed-to-create-file-w","errorCode":null,"errorMessage":"failed to create file: %w","messagePattern":"failed to create file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/input/formats/openapi/downloader.go","lineNumber":118,"sourceCode":"\tmodifiedJSON, err := json.Marshal(spec)\n\tif err != nil {\n\t\treturn \"\", errors.Wrap(err, \"failed to marshal modified spec\")\n\t}\n\n\t// Create output directory\n\topenapiDir := filepath.Join(tmpDir, \"openapi\")\n\tif err := os.MkdirAll(openapiDir, 0755); err != nil {\n\t\treturn \"\", errors.Wrap(err, \"failed to create openapi directory\")\n\t}\n\n\t// Generate filename\n\tfilename := fmt.Sprintf(\"openapi-spec-%d.json\", time.Now().Unix())\n\tfilePath := filepath.Join(openapiDir, filename)\n\n\t// Write file\n\tfile, err := os.Create(filePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create file: %w\", err)\n\t}\n\n\tdefer func() {\n\t\t_ = file.Close()\n\t}()\n\n\tif _, writeErr := file.Write(modifiedJSON); writeErr != nil {\n\t\t_ = os.Remove(filePath)\n\t\treturn \"\", errors.Wrap(writeErr, \"failed to write OpenAPI spec to file\")\n\t}\n\n\treturn filePath, nil\n}\n\n// SupportedExtensions returns the list of supported file extensions for OpenAPI\nfunc (d *OpenAPIDownloader) SupportedExtensions() []string {\n\treturn []string{\".json\"}\n}","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/projectdiscovery/nuclei/blob/265b3a3dec374741614e342f813c10f8b38d2bb7/pkg/input/formats/openapi/downloader.go#L100-L136","documentation":"After downloading and rewriting an OpenAPI spec, the downloader writes it to <TempDir>/openapi/openapi-spec-<unixtime>.json; os.Create on that path failed and the underlying filesystem error (permission denied, no such file or directory, read-only file system, disk full) is wrapped with %w. TempDir comes from the InputOptions.TempDir the caller (input provider) supplied.","triggerScenarios":"TempDir unset or pointing at a non-existent/read-only location; containers with a read-only rootfs and no writable /tmp; SELinux/AppArmor denying writes; disk exhausted; a file already existing where the openapi directory should be created; path too long.","commonSituations":"Running nuclei in hardened Docker/Kubernetes pods with read-only filesystems; minimal images lacking /tmp; CI runners with tiny tmpfs quotas; SDK callers passing an empty or relative TempDir.","solutions":["Set a writable TempDir (InputOptions.TempDir) or ensure $TMPDIR points at a writable directory","Verify with `touch <tmpdir>/openapi/test` that the effective user can create files there","In containers, mount an emptyDir/tmpfs at /tmp or set TMPDIR to a writable volume","Free disk space or raise the tmpfs size limit if the volume is full"],"exampleFix":"// SDK usage: pass a writable temp dir\n// before\nopts := provider.InputOptions{Options: options}\n// after\nopts := provider.InputOptions{\n    Options: options,\n    TempDir: os.TempDir(), // or a known-writable dir like \"/var/tmp/nuclei\"\n}","handlingStrategy":"validation","validationCode":"dir := filepath.Join(tempDir, \"openapi\")\nif err := os.MkdirAll(dir, 0o755); err != nil {\n    return fmt.Errorf(\"temp dir not writable: %w\", err)\n}\nprobe, err := os.Create(filepath.Join(dir, \".writecheck\"))\nif err != nil {\n    return fmt.Errorf(\"cannot create files in %s: %w\", dir, err)\n}\nprobe.Close()\nos.Remove(probe.Name())","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to create file\") {\n    // point TempDir at a writable volume and retry once; otherwise fail with the FS error\n}","preventionTips":["Set InputOptions.TempDir (or $TMPDIR) to a known-writable path in containers","Mount an emptyDir/tmpfs at /tmp in hardened pods","Monitor disk space in long-running scan workers"],"tags":["filesystem","permissions","io","temp-dir","openapi"],"backgroundTag":null,"analyzedSha":"265b3a3dec374741614e342f813c10f8b38d2bb7","analyzedAt":"2026-08-15T20:05:51.855Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}