{"record":{"id":"d818c8b89dc9c1d7","repo":"golangci/golangci-lint","slug":"constructing-mapstructure-decoder-w","errorCode":null,"errorMessage":"constructing mapstructure decoder: %w","messagePattern":"constructing mapstructure decoder: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/migrate/fakeloader/fakeloader.go","lineNumber":39,"sourceCode":"\tdefer func() { _ = file.Close() }()\n\n\traw := map[string]any{}\n\n\terr = parser.Decode(file, raw)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// NOTE: this is inspired by viper internals.\n\tcc := &mapstructure.DecoderConfig{\n\t\tResult:           old,\n\t\tWeaklyTypedInput: true,\n\t\tDecodeHook:       config.DecodeHookFunc(),\n\t}\n\n\tdecoder, err := mapstructure.NewDecoder(cc)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"constructing mapstructure decoder: %w\", err)\n\t}\n\n\terr = decoder.Decode(raw)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"decoding configuration file: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":21,"sourceCodeEnd":49,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/migrate/fakeloader/fakeloader.go#L21-L49","documentation":"Load wraps the error from mapstructure.NewDecoder when the decoder with the library's DecodeHookFunc and WeaklyTypedInput options cannot be constructed. This almost only fails if the provided DecodeHookFunc itself is invalid, so it signals an internal configuration-decoding setup problem in the migrate tooling rather than a user config problem.","triggerScenarios":"config.DecodeHookFunc() returns an invalid hook composition (e.g. a nil hook or malformed DecodeHook chain) passed into mapstructure.DecoderConfig, causing NewDecoder validation to fail.","commonSituations":"Encountered after upgrading golangci-lint or its config dependency where the decode hook setup changed; custom builds with a patched config package; effectively never caused by the user's YAML/TOML file.","solutions":["Upgrade to the latest golangci-lint release; this indicates an internal bug.","Check the golangci-lint issue tracker for known 'constructing mapstructure decoder' reports.","If using a custom build, verify config.DecodeHookFunc() returns a valid mapstructure.DecodeHookFunc.","Report a bug with the full error chain and version (golangci-lint version) if it persists."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := fakeloader.Load(srcPath, &old); err != nil {\n    if strings.Contains(err.Error(), \"constructing mapstructure decoder\") {\n        // internal bug: upgrade golangci-lint or report issue\n    }\n    return err\n}","preventionTips":["Keep golangci-lint updated to the latest release.","Avoid custom builds patching config.DecodeHookFunc.","Report reproducible cases upstream with version info."],"tags":["go","mapstructure","config","internal-bug"],"backgroundTag":"decoder-construction-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}