{"record":{"id":"bf5391df042555f5","repo":"gohugoio/hugo","slug":"invalid-webp-config-w","errorCode":null,"errorMessage":"invalid webp config: %w","messagePattern":"invalid webp config: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/config.go","lineNumber":571,"sourceCode":"}\n\nvar validMetaSources = map[string]bool{\n\t\"exif\": true,\n\t\"iptc\": true,\n\t\"xmp\":  true,\n}\n\nfunc (cfg *ImagingConfig) init() error {\n\tcfg.BgColor = strings.ToLower(strings.TrimPrefix(cfg.BgColor, \"#\"))\n\tcfg.Anchor = strings.ToLower(cfg.Anchor)\n\tcfg.ResampleFilter = strings.ToLower(cfg.ResampleFilter)\n\tcfg.Hint = strings.ToLower(cfg.Hint)\n\tcfg.Compression = strings.ToLower(cfg.Compression)\n\tif err := cfg.Jpeg.init(cfg); err != nil {\n\t\treturn fmt.Errorf(\"invalid jpeg config: %w\", err)\n\t}\n\tif err := cfg.Webp.init(cfg); err != nil {\n\t\treturn fmt.Errorf(\"invalid webp config: %w\", err)\n\t}\n\tif err := cfg.Avif.init(cfg); err != nil {\n\t\treturn fmt.Errorf(\"invalid avif config: %w\", err)\n\t}\n\tif cfg.Quality < 0 || cfg.Quality > 100 {\n\t\treturn fmt.Errorf(\"imaging.quality must be between 1 and 100 inclusive, got %d\", cfg.Quality)\n\t}\n\n\tif cfg.Anchor == \"\" {\n\t\tcfg.Anchor = smartCropIdentifier\n\t}\n\n\tif strings.TrimSpace(cfg.Exif.IncludeFields) == \"\" && strings.TrimSpace(cfg.Exif.ExcludeFields) == \"\" {\n\t\t// Don't change this for no good reason. Please don't.\n\t\tcfg.Exif.ExcludeFields = \"GPS|Exif|Exposure[M|P|B]|Contrast|Resolution|Sharp|JPEG|Metering|Sensing|Saturation|ColorSpace|Flash|WhiteBalance\"\n\t}\n\n\tif len(cfg.Meta.Fields) == 0 {","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/config.go#L553-L589","documentation":"Wrapper error returned by ImagingConfig.init() when the WebP sub-configuration (cfg.Webp.init) fails validation. The %w verb wraps the specific underlying failure so the root cause (hint, method, compression, or quality) is preserved in the error chain. This is a fail-fast config validation that runs at Hugo startup when the [imaging] namespace is decoded.","triggerScenarios":"Setting [imaging.webp] in hugo.toml with an invalid hint value (e.g. \"photograph\"), a method outside 0-6, a compression string other than lossy/lossless, or a quality outside 1-100. Also triggered programmatically by constructing an ImagingConfig with an invalid WebpConfig and calling init().","commonSituations":"Copying an imaging config from an outdated blog post or different Hugo version; typos like \"lossles\" in compression; setting webp.method to 7 (off-by-one from the 0-6 range); mixing up AVIF settings into the WebP section.","solutions":["Read the wrapped error chain — the underlying message names the exact WebP field and allowed values (e.g. 'imaging.webp.method must be between 0 and 6, got 7').","Open hugo.toml and fix the [imaging.webp] values: hint ∈ {picture,photo,drawing,icon,text}, method ∈ [0,6], compression ∈ {lossy,lossless}, quality ∈ [1,100].","If you don't need custom WebP settings, remove the entire [imaging.webp] section to fall back to the defaults (lossy compression, photo hint, method 2, quality 75)."],"exampleFix":"# before (hugo.toml)\n[imaging.webp]\nquality = 90\nmethod = 7\ncompression = \"losless\"\n\n# after\n[imaging.webp]\nquality = 90\nmethod = 6\ncompression = \"lossless\"","handlingStrategy":"validation","validationCode":"// Validate WebP config before calling init()\nfunc validateWebpConfig(w WebpConfig, globalQuality int) error {\n    validHints := map[string]bool{\"picture\":true,\"photo\":true,\"drawing\":true,\"icon\":true,\"text\":true}\n    h := strings.ToLower(w.Hint)\n    if h != \"\" && !validHints[h] {\n        return fmt.Errorf(\"invalid webp hint %q\", h)\n    }\n    if w.Method < 0 || w.Method > 6 {\n        return fmt.Errorf(\"webp method %d out of range [0,6]\", w.Method)\n    }\n    c := strings.ToLower(w.Compression)\n    if c != \"\" && c != \"lossy\" && c != \"lossless\" {\n        return fmt.Errorf(\"invalid webp compression %q\", c)\n    }\n    q := w.Quality; if q == 0 { q = globalQuality }; if q == 0 { q = 75 }\n    if q < 1 || q > 100 {\n        return fmt.Errorf(\"webp quality %d out of range [1,100]\", q)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'hugo' after every config change to catch validation errors early during development, not in production.","Keep a validated baseline hugo.toml and diff against it when changing imaging settings.","Remember webp.method is 0-6 (0-indexed) while avif.encoderSpeed is 1-10 (1-indexed) — don't mix them up."],"tags":["hugo","imaging","webp","config-validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}