{"record":{"id":"a71c8a4a46e8c06c","repo":"owasp-amass/amass","slug":"failed-to-create-the-output-file-s-v","errorCode":null,"errorMessage":"failed to create the output file %s: %v","messagePattern":"failed to create the output file (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/file.go","lineNumber":52,"sourceCode":"\nfunc CreateDefaultConfigFiles(dirpath string) error {\n\tfor _, filename := range resources.DefaultFilesList {\n\t\tfilepath := filepath.Join(dirpath, filename)\n\t\tif _, err := os.Stat(filepath); !os.IsNotExist(err) {\n\t\t\t// If the file already exists, skip creating it\n\t\t\tcontinue\n\t\t}\n\n\t\tfile, err := resources.GetResourceFile(filename)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to obtain the embedded file %s: %v\", filename, err)\n\t\t}\n\t\tdefer func() { _ = file.Close() }()\n\n\t\t// Create the default config file in the specified directory\n\t\toutFile, err := os.Create(filepath)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create the output file %s: %v\", filepath, err)\n\t\t}\n\t\tdefer func() { _ = outFile.Close() }()\n\n\t\tif _, err := io.Copy(outFile, file); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy the file %s: %v\", filepath, err)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":34,"sourceCodeEnd":62,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/internal/tools/file.go#L34-L62","documentation":"CreateDefaultConfigFiles creates each default config file with os.Create in the target directory. This error wraps any os.Create failure, meaning the destination file could not be created at filepath.","triggerScenarios":"The output directory does not exist (CreateOutputDirectory not called first or failed silently), the directory is not writable, filepath is actually a directory, or the path is invalid/too long.","commonSituations":"A directory with the same name as a config file exists in the output dir; read-only output volume in Docker/Kubernetes; the tool runs as a non-root user against a root-owned config directory.","solutions":["Ensure CreateOutputDirectory(dirpath) succeeded before calling CreateDefaultConfigFiles","Verify dirpath is writable by the running user (touch dirpath/.write-test)","Check that no directory exists with the same name as the target config file and remove/rename it","Run as a user with write access to the output directory, or pick a writable one"],"exampleFix":"// before\nif err := CreateDefaultConfigFiles(dirpath); err != nil { ... }\n// after\nif err := CreateOutputDirectory(dirpath); err != nil { return err }\nif err := CreateDefaultConfigFiles(dirpath); err != nil { return err }","handlingStrategy":"validation","validationCode":"if err := tools.CreateOutputDirectory(dirpath); err != nil {\n\treturn err\n}\nif st, err := os.Stat(dirpath); err != nil || !st.IsDir() {\n\treturn fmt.Errorf(\"%s is not a usable directory\", dirpath)\n}\nprobe := filepath.Join(dirpath, \".write-test\")\nif err := os.WriteFile(probe, nil, 0600); err != nil {\n\treturn fmt.Errorf(\"directory %s is not writable: %v\", dirpath, err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":"if err := tools.CreateDefaultConfigFiles(dirpath); err != nil {\n\tvar perr *fs.PathError\n\tif errors.As(err, &perr) && (errors.Is(perr.Err, os.ErrPermission) || errors.Is(perr.Err, os.ErrNotExist)) {\n\t\t// re-create the directory then retry once\n\t\tif tools.CreateOutputDirectory(dirpath) == nil {\n\t\t\terr = tools.CreateDefaultConfigFiles(dirpath)\n\t\t}\n\t}\n\tif err != nil { return err }\n}","preventionTips":["Always call CreateOutputDirectory before CreateDefaultConfigFiles","Avoid naming directories the same as expected config files inside the output dir","Run the tool as a user with write access to the output location","Add a writability preflight check in deployment scripts"],"tags":["go","filesystem","file-create","permissions"],"backgroundTag":"file-write-failed","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}