{"record":{"id":"d9c37a03e7f497ac","repo":"wavetermdev/waveterm","slug":"path-is-a-directory-not-an-image-file","errorCode":null,"errorMessage":"path is a directory, not an image file","messagePattern":"path is a directory, not an image file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-setbg.go","lineNumber":163,"sourceCode":"\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\n\t\t\tswitch {\n\t\t\tcase setBgTile:\n\t\t\t\tbgStyle += \" repeat\"","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-setbg.go#L145-L181","documentation":"Returned by wsh setbg when the given path exists but is a directory, which cannot be used as a background image.","triggerScenarios":"`wsh setbg ~/Pictures` or `wsh setbg .` — passing a directory path instead of an image file.","commonSituations":"Users pointing at a wallpaper *folder* instead of a file inside it; autocomplete picking a directory; scripts that iterate directories without filtering to files.","solutions":["Pass the path to an actual image file inside the directory, e.g. `wsh setbg ~/Pictures/wall.jpg`","Check with `test -f <path>` in scripts before invoking setbg","Use `wsh setbg $(ls ~/Pictures/*.png | head -1)` style expansion if you want the first image in a folder"],"exampleFix":"// before\nwsh setbg ~/Pictures/wallpapers\n// after\nwsh setbg ~/Pictures/wallpapers/mountain.jpg","handlingStrategy":"validation","validationCode":"# require a regular file, not a directory\nif [ -d \"$IMG\" ]; then echo \"$IMG is a directory\" >&2; exit 1; fi\nwsh setbg \"$IMG\"","typeGuard":"function isRegularFile(p) {\n  try { return require(\"fs\").statSync(p).isFile(); } catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Use tab-completion to pick files, not directories","In scripts iterating folders, filter to regular files (find -type f)","Check the argument ends with an image extension as a heuristic"],"tags":["cli","filesystem","validation"],"backgroundTag":"not-a-file","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}