multica-ai/multica · error
write file: %w
Error message
write file: %w
What it means
Final write of the downloaded bytes with os.WriteFile to destPath = filepath.Join(outputDir, filename). Wraps OS write errors: permission denied, destination is a directory, disk full, or name too long.
Source
Thrown at server/cmd/multica/cmd_attachment.go:172
// Download the file content.
data, err := client.DownloadFile(ctx, downloadURL)
if err != nil {
return fmt.Errorf("download file: %w", err)
}
// Write to the output directory, creating it if needed so `-o` works
// against a directory that does not exist yet (the help example's
// `-o ./attachments` in a clean workdir).
outputDir, _ := cmd.Flags().GetString("output-dir")
if outputDir != "" {
if err := os.MkdirAll(outputDir, 0o755); err != nil {
return fmt.Errorf("create output directory: %w", err)
}
}
destPath := filepath.Join(outputDir, filename)
if err := os.WriteFile(destPath, data, 0o644); err != nil {
return fmt.Errorf("write file: %w", err)
}
// Print the absolute path so agents can reference the file.
abs, err := filepath.Abs(destPath)
if err != nil {
abs = destPath
}
fmt.Fprintln(os.Stderr, "Downloaded:", abs)
// Also print as JSON for --output json compatibility.
return cli.PrintJSON(os.Stdout, map[string]any{
"id": strVal(att, "id"),
"filename": filename,
"path": abs,
"size": strVal(att, "size_bytes"),
})
}
View on GitHub (pinned to 2c0912b6ec)
Solutions
- Check `df -h <dir>` for space and `ls -l` the destination for a directory/filename collision; rename or remove the conflict
- Ensure the output directory is writable by the current user
- Download to a different output dir (-o /tmp/att) to isolate a bad destination
- If filename looks pathological, rename after download
Defensive patterns
Strategy: validation
Validate before calling
# check for directory/filename collision and writability before download
[ ! -d "./attachments/$expected_name" ] || { echo 'name collides with a directory' >&2; exit 1; }
[ -w ./attachments ] || { echo 'output dir not writable' >&2; exit 1; } Prevention
- Download into an empty scratch dir per attachment to avoid filename collisions
- Monitor disk space in long-running download loops
When it happens
Trigger: The server-supplied filename collides with an existing directory name in the output dir; output dir not writable; disk full; filename from metadata containing path separators or being extremely long (filesystem limit).
Common situations: Attachments named like `data` colliding with an existing `data/` directory; running as non-root into /mnt dirs; full disks on small VMs/containers; unusual unicode filenames from other OSes hitting filesystem limits.
Related errors
- create output directory: %w
- read file %s: %w
- get attachment: %w
- attachment has no download URL
- download file: %w
AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15).
Data as JSON: /api/errors/44b395873579daee.
Report an issue: GitHub.