{"record":{"id":"85447d310c732915","repo":"gohugoio/hugo","slug":"invalid-avif-config-w","errorCode":null,"errorMessage":"invalid avif config: %w","messagePattern":"invalid avif config: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/config.go","lineNumber":574,"sourceCode":"\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 {\n\t\t// Default: include all fields except technical metadata.\n\t\t// Don't change this for no good reason. Please don't.\n\t\tcfg.Meta.Fields = []string{","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/config.go#L556-L592","documentation":"Wrapper error returned by ImagingConfig.init() when the AVIF sub-configuration (cfg.Avif.init) fails validation. The %w wraps the specific underlying AVIF failure (hint, encoderSpeed, compression, or quality). Runs at startup during the [imaging] namespace decode.","triggerScenarios":"Setting [imaging.avif] in hugo.toml with an invalid hint, an encoderSpeed outside 1-10, a compression value other than lossy/lossless, or quality outside 1-100. Also triggered by a programmatic ImagingConfig with a bad AvifConfig.","commonSituations":"Setting encoderSpeed to 0 (the valid floor is 1, not 0); setting encoderSpeed too low (e.g. 1) causing extremely long build times even before hitting this error; typo in compression; confusing quality with encoderSpeed.","solutions":["Inspect the wrapped error for the exact AVIF field that failed and its allowed range.","Fix [imaging.avif] in hugo.toml: hint ∈ {picture,photo,drawing,icon,text}, encoderSpeed ∈ [1,10], compression ∈ {lossy,lossless}, quality ∈ [1,100].","Remove the [imaging.avif] section entirely to use the defaults (lossy, photo hint, encoderSpeed 10, quality 60)."],"exampleFix":"# before (hugo.toml)\n[imaging.avif]\nquality = 50\nencoderSpeed = 0\nhint = \"photograph\"\n\n# after\n[imaging.avif]\nquality = 50\nencoderSpeed = 1\nhint = \"photo\"","handlingStrategy":"validation","validationCode":"// Validate AVIF config before calling init()\nfunc validateAvifConfig(a AvifConfig, globalQuality int) error {\n    validHints := map[string]bool{\"picture\":true,\"photo\":true,\"drawing\":true,\"icon\":true,\"text\":true}\n    h := strings.ToLower(a.Hint)\n    if h != \"\" && !validHints[h] {\n        return fmt.Errorf(\"invalid avif hint %q\", h)\n    }\n    if a.EncoderSpeed < 1 || a.EncoderSpeed > 10 {\n        return fmt.Errorf(\"avif encoderSpeed %d out of range [1,10]\", a.EncoderSpeed)\n    }\n    c := strings.ToLower(a.Compression)\n    if c != \"\" && c != \"lossy\" && c != \"lossless\" {\n        return fmt.Errorf(\"invalid avif compression %q\", c)\n    }\n    q := a.Quality; if q == 0 { q = globalQuality }; if q == 0 { q = 60 }\n    if q < 1 || q > 100 {\n        return fmt.Errorf(\"avif quality %d out of range [1,100]\", q)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["AVIF encoderSpeed 1 is extremely slow — start from the default 10 and lower cautiously.","AVIF quality needs lower values than JPEG for equivalent quality (AVIF 50 ≈ JPEG 80 visually).","Validate config in a pre-commit hook or CI step with 'hugo --renderToMemory' to catch errors before deploy."],"tags":["hugo","imaging","avif","config-validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}