owasp-amass/amass · error
failed to copy the file %s: %v
Error message
failed to copy the file %s: %v
What it means
After creating the destination file, CreateDefaultConfigFiles copies the embedded file contents with io.Copy. This error means the copy operation failed — either writing to the destination file or (less likely) reading the embedded source failed mid-stream.
Source
Thrown at internal/tools/file.go:57
// 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)
Solutions
- Check free disk space and any quota (df -h, du on the volume)
- Re-run the tool; if a partially written config remains, delete it first (os.Stat with the exists check will skip a truncated file otherwise)
- Avoid running multiple instances concurrently against the same output directory
- Check dmesg/journal for filesystem I/O errors and move the output directory to healthy storage
Example fix
// before
if _, err := io.Copy(outFile, file); err != nil { return ... }
// after
if _, err := io.Copy(outFile, file); err != nil {
outFile.Close()
os.Remove(filepath) // drop partial file so next run recreates it
return fmt.Errorf("failed to copy the file %s: %v", filepath, err)
} Defensive patterns
Strategy: retry
Validate before calling
st, err := os.Stat(dirpath)
if err != nil || !st.IsDir() { return fmt.Errorf("output dir unusable") }
if us := getDiskFree(dirpath); us < 10*1024*1024 { return fmt.Errorf("less than 10MB free") } Try / catch
for attempt := 0; attempt < 2; attempt++ {
err := tools.CreateDefaultConfigFiles(dirpath)
if err == nil { break }
if strings.Contains(err.Error(), "failed to copy the file") && attempt == 0 {
os.RemoveAll(filepath.Join(dirpath)) // clear partial files
_ = tools.CreateOutputDirectory(dirpath)
continue
}
return err
} Prevention
- Monitor disk space/quota before running heavy jobs
- Do not share an output directory between concurrent tool instances
- Remove partial/truncated config files after failed runs
- Watch dmesg/journal for I/O errors on the storage backing the output dir
When it happens
Trigger: Disk becomes full while writing, the destination file descriptor hits an I/O error (bad sector, quota exceeded, network mount dropout), or the file is truncated/removed concurrently.
Common situations: Small disk partitions or container quota limits exhausted during initialization; NFS/EBS volumes losing connectivity mid-copy; concurrent runs racing on the same output 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 obtain the path for the output directory
- failed to get executable path: %w
- mkdir failed for %s: %v
- failed to set permissions to 0755 for %s: %v
- failed to create the output file %s: %v
AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06).
Data as JSON: /api/errors/a3be93332e586bc0.
Report an issue: GitHub.