multica-ai/multica · error

create output directory: %w

Error message

create output directory: %w

What it means

When -o/--output-dir is set, the download command creates the directory with os.MkdirAll before writing. This error wraps filesystem failures to create it: permission denied on a parent, a path component that is a regular file, or read-only filesystem.

Source

Thrown at server/cmd/multica/cmd_attachment.go:166

	filename := filepath.Base(strVal(att, "filename"))
	if filename == "" || filename == "." {
		filename = args[0]
	}

	// 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"),

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. Check the path: `ls -la <parent>` and remove/rename any file conflicting with the directory name
  2. Choose a writable output dir (under $HOME or /tmp) or fix permissions/ownership
  3. If in a container, ensure the output volume is mounted rw

Example fix

# before: a file named 'attachments' exists
multica attachment download "$id" -o ./attachments

# after
rm ./attachments   # or pick another dir
multica attachment download "$id" -o ./attachments
Defensive patterns

Strategy: validation

Validate before calling

# ensure output target is creatable
out=./attachments
[ ! -f "$out" ] || { echo "a file named $out exists" >&2; exit 1; }
mkdir -p "$out" 2>/dev/null || { echo "cannot create $out" >&2; exit 1; }

Prevention

When it happens

Trigger: `-o ./attachments` where a file named `attachments` already exists; output dir under a directory the user cannot write (e.g. /opt, /var); read-only mount or full disk inode exhaustion.

Common situations: Scripts running as a different user than expected; leftover file with the same name as the intended directory; container with a read-only volume mounted at the output path.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/0912cdf1bece4bbe. Report an issue: GitHub.