{"record":{"id":"0912cdf1bece4bbe","repo":"multica-ai/multica","slug":"create-output-directory-w","errorCode":null,"errorMessage":"create output directory: %w","messagePattern":"create output directory: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/multica/cmd_attachment.go","lineNumber":166,"sourceCode":"\n\tfilename := filepath.Base(strVal(att, \"filename\"))\n\tif filename == \"\" || filename == \".\" {\n\t\tfilename = args[0]\n\t}\n\n\t// Download the file content.\n\tdata, err := client.DownloadFile(ctx, downloadURL)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"download file: %w\", err)\n\t}\n\n\t// Write to the output directory, creating it if needed so `-o` works\n\t// against a directory that does not exist yet (the help example's\n\t// `-o ./attachments` in a clean workdir).\n\toutputDir, _ := cmd.Flags().GetString(\"output-dir\")\n\tif outputDir != \"\" {\n\t\tif err := os.MkdirAll(outputDir, 0o755); err != nil {\n\t\t\treturn fmt.Errorf(\"create output directory: %w\", err)\n\t\t}\n\t}\n\tdestPath := filepath.Join(outputDir, filename)\n\n\tif err := os.WriteFile(destPath, data, 0o644); err != nil {\n\t\treturn fmt.Errorf(\"write file: %w\", err)\n\t}\n\n\t// Print the absolute path so agents can reference the file.\n\tabs, err := filepath.Abs(destPath)\n\tif err != nil {\n\t\tabs = destPath\n\t}\n\tfmt.Fprintln(os.Stderr, \"Downloaded:\", abs)\n\n\t// Also print as JSON for --output json compatibility.\n\treturn cli.PrintJSON(os.Stdout, map[string]any{\n\t\t\"id\":       strVal(att, \"id\"),","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_attachment.go#L148-L184","documentation":"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.","triggerScenarios":"`-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.","commonSituations":"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.","solutions":["Check the path: `ls -la <parent>` and remove/rename any file conflicting with the directory name","Choose a writable output dir (under $HOME or /tmp) or fix permissions/ownership","If in a container, ensure the output volume is mounted rw"],"exampleFix":"# before: a file named 'attachments' exists\nmultica attachment download \"$id\" -o ./attachments\n\n# after\nrm ./attachments   # or pick another dir\nmultica attachment download \"$id\" -o ./attachments","handlingStrategy":"validation","validationCode":"# ensure output target is creatable\nout=./attachments\n[ ! -f \"$out\" ] || { echo \"a file named $out exists\" >&2; exit 1; }\nmkdir -p \"$out\" 2>/dev/null || { echo \"cannot create $out\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick output dirs under writable locations ($HOME, /tmp) in scripts","Pre-create and permission the output dir in setup steps"],"tags":["cli","attachment","filesystem","download"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}