owasp-amass/amass · error
failed to create the output file
Error message
failed to create the output file %s: %v
What it means
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.
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
Example fix
// before
if err := CreateDefaultConfigFiles(dirpath); err != nil { ... }
// after
if err := CreateOutputDirectory(dirpath); err != nil { return err }
if err := CreateDefaultConfigFiles(dirpath); err != nil { return err } Defensive patterns
Strategy: validation
Validate before calling
if err := tools.CreateOutputDirectory(dirpath); err != nil {
return err
}
if st, err := os.Stat(dirpath); err != nil || !st.IsDir() {
return fmt.Errorf("%s is not a usable directory", dirpath)
}
probe := filepath.Join(dirpath, ".write-test")
if err := os.WriteFile(probe, nil, 0600); err != nil {
return fmt.Errorf("directory %s is not writable: %v", dirpath, err)
}
os.Remove(probe) Try / catch
if err := tools.CreateDefaultConfigFiles(dirpath); err != nil {
var perr *fs.PathError
if errors.As(err, &perr) && (errors.Is(perr.Err, os.ErrPermission) || errors.Is(perr.Err, os.ErrNotExist)) {
// re-create the directory then retry once
if tools.CreateOutputDirectory(dirpath) == nil {
err = tools.CreateDefaultConfigFiles(dirpath)
}
}
if err != nil { return err }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- failed to set permissions to 0755 for
- mkdir failed for
- failed to copy the file
- failed to create the log directory
- failed to create the temp dir
AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06).
Data as JSON: /api/errors/a71c8a4a46e8c06c.
Report an issue: GitHub.
Appendix: source
Thrown at internal/tools/file.go:52
func CreateDefaultConfigFiles(dirpath string) error {
for _, filename := range resources.DefaultFilesList {
filepath := filepath.Join(dirpath, filename)
if _, err := os.Stat(filepath); !os.IsNotExist(err) {
// If the file already exists, skip creating it
continue
}
file, err := resources.GetResourceFile(filename)
if err != nil {
return fmt.Errorf("failed to obtain the embedded file %s: %v", filename, err)
}
defer func() { _ = file.Close() }()
// Create the default config file in the specified directory
outFile, err := os.Create(filepath)
if err != nil {
return fmt.Errorf("failed to create the output file %s: %v", filepath, err)
}
defer func() { _ = outFile.Close() }()
if _, err := io.Copy(outFile, file); err != nil {
return fmt.Errorf("failed to copy the file %s: %v", filepath, err)
}
}
return nil
}
View on GitHub (pinned to 79299dce87)