{"record":{"id":"5ce437b126219a9c","repo":"wavetermdev/waveterm","slug":"file-does-not-appear-to-be-a-valid-image-detected","errorCode":null,"errorMessage":"file does not appear to be a valid image (detected type: %s)","messagePattern":"file does not appear to be a valid image \\(detected type: (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-setbg.go","lineNumber":171,"sourceCode":"\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\"\n\t\t\tcase setBgCenter:\n\t\t\t\tbgStyle += fmt.Sprintf(\" no-repeat center/%s\", setBgSize)\n\t\t\tdefault:\n\t\t\t\tbgStyle += \" center/cover no-repeat\"\n\t\t\t}\n\t\t}\n\n\t\tmeta[\"bg\"] = bgStyle","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-setbg.go#L153-L189","documentation":"setbg runs fileutil.DetectMimeType on the file and only accepts jpeg, png, gif, webp, and svg+xml. If the detected MIME type is anything else (or text/plain, application/octet-stream, empty), the command refuses with this message including the detected type. This prevents setting non-image data as a background.","triggerScenarios":"`wsh setbg file.txt`, `wsh setbg image.bmp` (BMP is unsupported), a renamed file (e.g. a .txt renamed to .png — content sniffing catches it), a corrupt/HTML error page downloaded as .jpg, or a file whose type could not be detected (reported as empty).","commonSituations":"Unsupported formats like BMP, TIFF, AVIF, HEIC; corrupted downloads; files downloaded from the web that are actually HTML; SVG served with wrong encoding.","solutions":["Convert the image to a supported format (png/jpeg/webp/gif/svg), e.g. with ImageMagick: `magick input.bmp output.png`","Read the detected type in the error message to see what the file actually is: `file <path>`","Re-download or re-export the image if it is corrupt or an HTML error page","Avoid BMP/TIFF/HEIC; convert to PNG first"],"exampleFix":"// before\nwsh setbg wallpaper.bmp\n// after\nmagick wallpaper.bmp wallpaper.png\nwsh setbg wallpaper.png","handlingStrategy":"validation","validationCode":"# check the detected type before calling wsh\nmime=$(file -b --mime-type \"$IMG\")\ncase \"$mime\" in\n  image/jpeg|image/png|image/gif|image/webp|image/svg+xml) ;;\n  *) echo \"unsupported type: $mime\" >&2; exit 1;;\nesac\nwsh setbg \"$IMG\"","typeGuard":"const SUPPORTED = new Set([\"image/jpeg\",\"image/png\",\"image/gif\",\"image/webp\",\"image/svg+xml\"]);\nfunction isSupportedImage(mime) {\n  return SUPPORTED.has(mime);\n}","tryCatchPattern":"try {\n  execSync(`wsh setbg \"${img}\"`, { stdio: \"pipe\" });\n} catch (e) {\n  const m = String(e.stderr).match(/detected type: (.*)\\)/);\n  if (m) console.error(`Convert the file; detected ${m[1]}`);\n  else throw e;\n}","preventionTips":["Convert BMP/TIFF/HEIC/AVIF to PNG or WebP beforehand","Verify downloaded images are real images (file <path>) and not HTML error pages","Do not trust file extensions; waveterm sniffs content"],"tags":["cli","filetype","validation"],"backgroundTag":"unsupported-file-type","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}