{"record":{"id":"041700f0cd70f254","repo":"wavetermdev/waveterm","slug":"resolving-image-path-v","errorCode":null,"errorMessage":"resolving image path: %v","messagePattern":"resolving image path: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-setbg.go","lineNumber":155,"sourceCode":"\t\tmeta[\"bg:opacity\"] = setBgOpacity\n\n\t\tinput := args[0]\n\t\tvar bgStyle string\n\n\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","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-setbg.go#L137-L173","documentation":"When the positional argument is not a hex color or CSS color name, setbg treats it as an image path and calls filepath.Abs(wavebase.ExpandHomeDirSafe(input)). filepath.Abs can fail on malformed paths (e.g. nil bytes, empty path after expansion, or OS-specific path errors). The underlying OS error is wrapped with this message.","triggerScenarios":"`wsh setbg` with a positional argument that fails filepath.Abs — typically an empty string argument, a path containing NUL bytes, or a path that cannot be made absolute on the current OS.","commonSituations":"Shell passing an empty quoted string (`wsh setbg \"\"`); variables that expand to nothing (`wsh setbg $IMG_PATH` with IMG_PATH unset leaves zero args, but `wsh setbg \"$IMG_PATH\"` gives an empty string); corrupted input from scripts.","solutions":["Check the argument is a non-empty, well-formed path before running: `[ -n \"$IMG\" ] && wsh setbg \"$IMG\"`","Verify ExpandHomeDirSafe handled your ~ prefix correctly; try an absolute path instead","Inspect the wrapped OS error text after the colon for the exact cause"],"exampleFix":"// before\nwsh setbg \"$IMG_PATH\"\n// after\nif [ -z \"$IMG_PATH\" ]; then echo \"IMG_PATH is empty\"; exit 1; fi\nwsh setbg \"$IMG_PATH\"","handlingStrategy":"validation","validationCode":"# ensure the argument is a non-empty path before calling wsh\nif [ -z \"$IMG\" ]; then echo \"empty image path\" >&2; exit 1; fi\ncase \"$IMG\" in *$'\\0'*) echo \"path contains NUL byte\" >&2; exit 1;; esac","typeGuard":null,"tryCatchPattern":"try {\n  execSync(`wsh setbg \"${img}\"`, { stdio: \"pipe\" });\n} catch (e) {\n  if (String(e.stderr).includes(\"resolving image path\")) {\n    console.error(\"Bad path argument:\", img);\n  } else throw e;\n}","preventionTips":["Check variables are non-empty before interpolation","Prefer absolute paths over ~ expansion in scripts","Validate path shape before invoking the CLI"],"tags":["cli","filesystem","path-resolution"],"backgroundTag":"invalid-file-path","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}