wavetermdev/waveterm · error
resolving image path: %v
Error message
resolving image path: %v
What it means
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.
Source
Thrown at cmd/wsh/cmd/wshcmd-setbg.go:155
meta["bg:opacity"] = setBgOpacity
input := args[0]
var bgStyle string
// Check for hex color
if strings.HasPrefix(input, "#") {
if err := validateHexColor(input); err != nil {
return err
}
bgStyle = input
} else if CssColorNames[strings.ToLower(input)] {
// Handle CSS color name
bgStyle = strings.ToLower(input)
} else {
// Handle image input
absPath, err := filepath.Abs(wavebase.ExpandHomeDirSafe(input))
if err != nil {
return fmt.Errorf("resolving image path: %v", err)
}
fileInfo, err := os.Stat(absPath)
if err != nil {
return fmt.Errorf("cannot access image file: %v", err)
}
if fileInfo.IsDir() {
return fmt.Errorf("path is a directory, not an image file")
}
mimeType := fileutil.DetectMimeType(absPath, fileInfo, true)
switch mimeType {
case "image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml":
// Valid image type
default:
return fmt.Errorf("file does not appear to be a valid image (detected type: %s)", mimeType)
}
View on GitHub (pinned to a4447c1563)
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
Example fix
// before wsh setbg "$IMG_PATH" // after if [ -z "$IMG_PATH" ]; then echo "IMG_PATH is empty"; exit 1; fi wsh setbg "$IMG_PATH"
Defensive patterns
Strategy: validation
Validate before calling
# ensure the argument is a non-empty path before calling wsh if [ -z "$IMG" ]; then echo "empty image path" >&2; exit 1; fi case "$IMG" in *$'\0'*) echo "path contains NUL byte" >&2; exit 1;; esac
Try / catch
try {
execSync(`wsh setbg "${img}"`, { stdio: "pipe" });
} catch (e) {
if (String(e.stderr).includes("resolving image path")) {
console.error("Bad path argument:", img);
} else throw e;
} Prevention
- Check variables are non-empty before interpolation
- Prefer absolute paths over ~ expansion in scripts
- Validate path shape before invoking the CLI
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- getting absolute path: %w
- getting absolute path: %w
- getting absolute path of parent dir: %w
- file does not exist: %q
- getting file info: %w
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/041700f0cd70f254.
Report an issue: GitHub.