{"record":{"id":"4ff31c919ed13a7b","repo":"wavetermdev/waveterm","slug":"cannot-access-image-file-v","errorCode":null,"errorMessage":"cannot access image file: %v","messagePattern":"cannot access image file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-setbg.go","lineNumber":160,"sourceCode":"\t\t// Check for hex color\n\t\tif strings.HasPrefix(input, \"#\") {\n\t\t\tif err := validateHexColor(input); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tbgStyle = input\n\t\t} else if CssColorNames[strings.ToLower(input)] {\n\t\t\t// Handle CSS color name\n\t\t\tbgStyle = strings.ToLower(input)\n\t\t} else {\n\t\t\t// Handle image input\n\t\t\tabsPath, err := filepath.Abs(wavebase.ExpandHomeDirSafe(input))\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"resolving image path: %v\", err)\n\t\t\t}\n\n\t\t\tfileInfo, err := os.Stat(absPath)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"cannot access image file: %v\", err)\n\t\t\t}\n\t\t\tif fileInfo.IsDir() {\n\t\t\t\treturn fmt.Errorf(\"path is a directory, not an image file\")\n\t\t\t}\n\n\t\t\tmimeType := fileutil.DetectMimeType(absPath, fileInfo, true)\n\t\t\tswitch mimeType {\n\t\t\tcase \"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\", \"image/svg+xml\":\n\t\t\t\t// Valid image type\n\t\t\tdefault:\n\t\t\t\treturn fmt.Errorf(\"file does not appear to be a valid image (detected type: %s)\", mimeType)\n\t\t\t}\n\n\t\t\t// Create URL-safe path\n\t\t\tescapedPath := filepath.ToSlash(absPath)\n\t\t\tescapedPath = strings.ReplaceAll(escapedPath, \"'\", \"\\\\'\")\n\t\t\tbgStyle = fmt.Sprintf(\"url('%s')\", escapedPath)\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-setbg.go#L142-L178","documentation":"After resolving the absolute path, setbg calls os.Stat to confirm the file exists and is accessible. If Stat returns an error (file missing, permission denied, broken symlink, etc.) the error is wrapped as \"cannot access image file\". Nothing was changed; the background is untouched.","triggerScenarios":"`wsh setbg /path/to/missing.png`, a typo'd filename, a file deleted between lookup and call, a symlink pointing nowhere, or a file the current user lacks permission to stat (e.g. parent directory without +x).","commonSituations":"Typos in the image path; referencing files on an unmounted drive or remote share; sandboxed environments where the wsh process lacks filesystem access; case-sensitive filesystems where the extension case is wrong.","solutions":["Run `ls -l <path>` yourself to confirm the file exists and is readable","Fix typos or use tab-completion to get the exact path","Check permissions on the file and its parent directories (chmod/chown as appropriate)","If using ~, ensure ExpandHomeDirSafe resolved it; try the absolute path"],"exampleFix":"// before\nwsh setbg ~/wallpaper.png\n// after\n# verify first\nls -l ~/wallpaper.png && wsh setbg ~/wallpaper.png","handlingStrategy":"validation","validationCode":"# check accessibility before calling wsh\nif [ ! -f \"$IMG\" ] || [ ! -r \"$IMG\" ]; then\n  echo \"cannot read $IMG\" >&2; exit 1\nfi\nwsh setbg \"$IMG\"","typeGuard":"function fileExists(p) {\n  try { return require(\"fs\").statSync(p).isFile(); } catch { return false; }\n}","tryCatchPattern":"try {\n  execSync(`wsh setbg \"${img}\"`, { stdio: \"pipe\" });\n} catch (e) {\n  if (String(e.stderr).includes(\"cannot access image file\")) {\n    console.error(`File missing or unreadable: ${img}`);\n  } else throw e;\n}","preventionTips":["Test the path with ls/stat before invoking wsh","Watch for broken symlinks and unmounted drives","Remember Linux filesystems are case-sensitive; match the exact filename"],"tags":["cli","filesystem","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}