multica-ai/multica · error

read file %s: %w

Error message

read file %s: %w

What it means

The attachment upload command reads the local file with os.ReadFile before sending it. This error wraps the underlying os.ReadFile failure (the %w preserves the OS error: no such file, permission denied, is a directory, etc.).

Source

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

	if err != nil {
		return err
	}

	taskID, _ := cmd.Flags().GetString("task")
	if taskID == "" {
		taskID = client.TaskID
	}
	if taskID == "" {
		return fmt.Errorf("no chat task in context: run inside a chat task (MULTICA_TASK_ID set) or pass --task <id>")
	}

	path := args[0]
	if isHTTPURL(path) {
		return fmt.Errorf("upload accepts a local file path, not a URL: %s", path)
	}
	data, err := os.ReadFile(path)
	if err != nil {
		return fmt.Errorf("read file %s: %w", path, err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), cli.AtLeastAPITimeout(60*time.Second))
	defer cancel()

	att, err := client.UploadChatAttachment(ctx, data, path, taskID)
	if err != nil {
		return fmt.Errorf("upload attachment: %w", err)
	}

	filename := filepath.Base(path)
	// Escape markdown label metacharacters in the filename so a name like
	// `report[v2].pdf` does not truncate the snippet's label. Files render as a
	// block-level attachment card via `!file[...]( )`; images render inline via
	// `![...]( )`.
	label := escapeMarkdownLabel(filename)
	markdown := fmt.Sprintf("!file[%s](%s)", label, att.MarkdownURL)
	if strings.HasPrefix(att.ContentType, "image/") {

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. Verify the file exists and is readable: `ls -l <path>` / `test -r <path>`
  2. Use an absolute path or expand ~ explicitly (`~/x` is not expanded by Go's os.ReadFile; use $HOME/x)
  3. Fix permissions if needed: `chmod +r <file>` or run with appropriate privileges
  4. Confirm you passed a file, not a directory

Example fix

# before
multica attachment upload report.pdf   # run from wrong cwd

# after
multica attachment upload "$(pwd)/report.pdf"
# guard in shell:
[ -r "$f" ] || { echo "missing or unreadable: $f" >&2; exit 1; }
Defensive patterns

Strategy: validation

Validate before calling

# shell pre-check
[ -f "$path" ] && [ -r "$path" ] || { echo "missing/unreadable: $path" >&2; exit 1; }

Prevention

When it happens

Trigger: Passing a path that does not exist, a directory instead of a file, or a file the current user cannot read (ownership/permission mismatch, restrictive umask, read-only mount).

Common situations: Typos or wrong relative paths (command run from a different cwd than assumed); files created by another user or root; paths with unexpanded ~ or env vars; files on an unplugged network mount.

Related errors


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