{"record":{"id":"4a08a8ea683551ab","repo":"multica-ai/multica","slug":"file-not-found-w","errorCode":null,"errorMessage":"file not found: %w","messagePattern":"file not found: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/multica/cmd_agent.go","lineNumber":918,"sourceCode":"\tcli.PrintTable(os.Stdout, headers, rows)\n\treturn nil\n}\n\nfunc runAgentAvatar(cmd *cobra.Command, args []string) error {\n\tclient, err := newAPIClient(cmd)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfilePath, _ := cmd.Flags().GetString(\"file\")\n\tif filePath == \"\" {\n\t\treturn fmt.Errorf(\"--file is required\")\n\t}\n\n\t// Validate file exists.\n\tinfo, err := os.Stat(filePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"file not found: %w\", err)\n\t}\n\n\t// Validate extension.\n\text := strings.ToLower(filepath.Ext(filePath))\n\tvalidExts := map[string]bool{\".png\": true, \".jpg\": true, \".jpeg\": true, \".gif\": true, \".webp\": true}\n\tif !validExts[ext] {\n\t\treturn fmt.Errorf(\"unsupported file format %q: must be .png, .jpg, .jpeg, .gif, or .webp\", ext)\n\t}\n\n\t// Client-side size guard: reject files > 5MB.\n\tconst maxSize = 5 << 20 // 5 MB\n\tif info.Size() > maxSize {\n\t\treturn fmt.Errorf(\"file too large: %d bytes (max 5MB)\", info.Size())\n\t}\n\n\tfileData, err := os.ReadFile(filePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read file: %w\", err)","sourceCodeStart":900,"sourceCodeEnd":936,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_agent.go#L900-L936","documentation":"Wrapped error from os.Stat when the path given to `multica agent avatar --file` cannot be stat'd — the file (or a directory component) does not exist, or permissions deny the lookup. The underlying %w is a *fs.PathError carrying the OS-level cause.","triggerScenarios":"`--file ./avatr.png` with a typo, a relative path evaluated from the wrong working directory, a path containing an unexpanded `~`, or a file removed between composing the command and running it.","commonSituations":"Shell does not expand `~` inside quoted variables; scripts run from a different cwd than assumed; paths copied from another machine; permission-restricted directories.","solutions":["Check existence: `ls -l <path>`; fix the typo or use an absolute path","Quote but expand `~` yourself: use \"$HOME/avatar.png\" instead of '~/avatar.png'","Verify read permission on the file and execute permission on parent directories","In scripts, validate the path with `[ -f \"$F\" ]` before calling the CLI"],"exampleFix":"# before\nmultica agent avatar agt_1 --file '~/pictures/me.png'\n# Error: file not found: stat ~/pictures/me.png: no such file or directory\n\n# after\nmultica agent avatar agt_1 --file \"$HOME/pictures/me.png\"","handlingStrategy":"validation","validationCode":"[ -f \"$AVATAR_FILE\" ] || { echo \"file not found: $AVATAR_FILE\"; exit 1; }\nmultica agent avatar \"$AGENT_ID\" --file \"$AVATAR_FILE\"","typeGuard":"func fileExists(p string) bool {\n\t_, err := os.Stat(p)\n\treturn err == nil && !errors.Is(err, fs.ErrNotExist)\n}","tryCatchPattern":"info, err := os.Stat(filePath)\nif err != nil {\n\treturn fmt.Errorf(\"file not found: %w\", err)\n}","preventionTips":["Pre-check with [ -f ] in shell scripts","Use absolute paths; expand $HOME explicitly instead of relying on ~","Verify read permissions on the file before the command"],"tags":["cli","filesystem","validation","avatar"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}