{"record":{"id":"46d36ee2cbd01637","repo":"projectdiscovery/katana","slug":"error-creating-decoder-v","errorCode":null,"errorMessage":"error creating decoder: %v","messagePattern":"error creating decoder: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/output/output.go","lineNumber":434,"sourceCode":"\t}\n\n\tres, err := dsl.EvalExpr(dslExpr, resultMap)\n\tif err != nil && !ignoreErr(err) {\n\t\tgologger.Error().Msgf(\"Could not evaluate DSL expression: %s\\n\", err)\n\t\treturn false\n\t}\n\treturn res == true\n}\n\nfunc resultToMap(result Result) (map[string]interface{}, error) {\n\tresultMap := make(map[string]any)\n\tconfig := &mapstructure.DecoderConfig{\n\t\tTagName: \"json\",\n\t\tResult:  &resultMap,\n\t}\n\tdecoder, err := mapstructure.NewDecoder(config)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating decoder: %v\", err)\n\t}\n\terr = decoder.Decode(result)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error decoding: %v\", err)\n\t}\n\n\trequestMap := make(map[string]any)\n\tif err := mapstructure.Decode(result.Request, &requestMap); err == nil {\n\t\tfor k, v := range requestMap {\n\t\t\tresultMap[strcase.SnakeCase(k)] = v\n\t\t}\n\t}\n\n\tresponseMap := make(map[string]any)\n\tif err := mapstructure.Decode(result.Response, &responseMap); err == nil {\n\t\tfor k, v := range responseMap {\n\t\t\tif strings.ToLower(k) == \"headers\" {\n\t\t\t\tif headers, ok := v.(navigation.Headers); ok {","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/output/output.go#L416-L452","documentation":"mapstructure.NewDecoder failed while constructing a decoder for converting a result struct into a map using json tags. NewDecoder only errors on invalid DecoderConfig, practically meaning Result is not a non-nil pointer (here &resultMap is always valid), so this is nearly unreachable but defensively handled. If hit, DSL evaluation in evalDslExpr cannot proceed.","triggerScenarios":"resultToMap builds a DecoderConfig and NewDecoder rejects it — only possible if the Result target is nil or not a pointer, which would require resultMap to be nil or the config struct corrupted.","commonSituations":"Practically never seen in production; encountered when refactoring resultToMap (e.g., passing a nil map pointer or removing the & on Result) or when a vendored/patched mapstructure version has stricter config validation.","solutions":["Confirm DecoderConfig.Result is a non-nil pointer: Result: &resultMap with resultMap declared as map[string]any.","Pin/upgrade github.com/mitchellh/mapstructure to a stable version; a broken vendored copy can misbehave.","Log the underlying error (%v) — it states exactly which config field is invalid.","If a refactor introduced this, revert the change to the DecoderConfig construction."],"exampleFix":"// before\nvar resultMap map[string]any\nconfig := &mapstructure.DecoderConfig{TagName: \"json\", Result: resultMap}\n// after\nresultMap := make(map[string]any)\nconfig := &mapstructure.DecoderConfig{TagName: \"json\", Result: &resultMap}","handlingStrategy":"try-catch","validationCode":"if result == nil || reflect.ValueOf(result).Kind() != reflect.Ptr {\n    return nil, fmt.Errorf(\"resultToMap requires a non-nil pointer target\")\n}","typeGuard":"func isDecoderConfigValid(cfg *mapstructure.DecoderConfig) bool {\n    return cfg != nil && cfg.Result != nil && reflect.ValueOf(cfg.Result).Kind() == reflect.Ptr && !reflect.ValueOf(cfg.Result).IsNil()\n}","tryCatchPattern":"m, err := resultToMap(result)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"error creating decoder\") {\n        // programmer error in DecoderConfig construction — fail fast with stack trace\n    }\n}","preventionTips":["Always pass Result as a non-nil pointer to the destination map.","Keep mapstructure dependency on a pinned, stable version.","Cover resultToMap with a unit test so DecoderConfig regressions surface in CI."],"tags":["mapstructure","dsl","serialization"],"backgroundTag":"decoder-config-invalid","analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}