{"record":{"id":"d37d4f452df8be11","repo":"golangci/golangci-lint","slug":"failed-to-encode-configuration-w","errorCode":null,"errorMessage":"failed to encode configuration: %w","messagePattern":"failed to encode configuration: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/golinters/revive/revive.go","lineNumber":188,"sourceCode":"\n// This function mimics the GetConfig function of revive.\n// This allows to get default values and right types.\n// https://github.com/golangci/golangci-lint/issues/1745\n// https://github.com/mgechev/revive/blob/v1.13.0/config/config.go#L249\n// https://github.com/mgechev/revive/blob/v1.13.0/config/config.go#L198-L204\nfunc getConfig(cfg *config.ReviveSettings) (*lint.Config, error) {\n\tconf := defaultConfig()\n\n\t// Since the Go version is dynamic, this value must be neutralized in order to compare with a \"zero value\" of the configuration structure.\n\tzero := &config.ReviveSettings{Go: cfg.Go}\n\n\tif !reflect.DeepEqual(cfg, zero) {\n\t\trawRoot := createConfigMap(cfg)\n\t\tbuf := bytes.NewBuffer(nil)\n\n\t\terr := toml.NewEncoder(buf).Encode(rawRoot)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to encode configuration: %w\", err)\n\t\t}\n\n\t\tconf = &lint.Config{}\n\t\t_, err = toml.NewDecoder(buf).Decode(conf)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to decode configuration: %w\", err)\n\t\t}\n\t}\n\n\tnormalizeConfig(conf)\n\n\tfor k, r := range conf.Rules {\n\t\terr := r.Initialize()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error in config of rule %q: %w\", k, err)\n\t\t}\n\t\tconf.Rules[k] = r\n\t}","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/golinters/revive/revive.go#L170-L206","documentation":"getConfig converts the golangci-lint revive settings struct into a revive lint.Config by encoding it as TOML and decoding it back. If toml.NewEncoder(buf).Encode(rawRoot) fails — the settings map contains values TOML cannot represent — the encoder error is wrapped as \"failed to encode configuration\" and revive initialization fails.","triggerScenarios":"createConfigMap(cfg) produces a structure containing a type not encodable by the TOML writer (e.g. unsupported map key type, cyclic/odd nested values) for a non-zero revive settings struct, inside getConfig called from newWrapper.","commonSituations":"Exotic values in linters-settings.revive (custom rule configurations, unusual nested maps) that don't round-trip through TOML; golangci-lint/revive version mismatches changing config shapes; hand-edited configs with wrong types (string where number/table expected).","solutions":["Simplify/fix linters-settings.revive to use documented types: rules as name→options maps with scalar values.","Update golangci-lint (and its bundled revive) to the latest version — encoder incompatibilities are often fixed upstream.","Reduce the revive config to a minimal set of settings and re-add entries until the failing one is identified.","Report the inner %w cause upstream if a supported setting fails to encode."],"exampleFix":"# before\nlinters-settings:\n  revive:\n    rules:\n      - name: var-naming\n        arguments: [\"wrongPattern\"]\n# after (valid documented shape)\nlinters-settings:\n  revive:\n    rules:\n      - name: var-naming\n        arguments:\n          - maxLength: 40","handlingStrategy":"validation","validationCode":"// ensure revive settings only contain TOML-encodable values (scalars, arrays, string-keyed maps)\nfunc tomlSafe(v reflect.Value) error {\n    switch v.Kind() {\n    case reflect.Map:\n        if v.Type().Key().Kind() != reflect.String {\n            return errors.New(\"maps must have string keys for TOML\")\n        }\n    case reflect.Slice, reflect.Array, reflect.Struct, reflect.Ptr:\n        for i := 0; i < v.Len(); i++ {\n            if err := tomlSafe(v.Index(i)); err != nil { return err }\n        }\n    case reflect.String, reflect.Bool, reflect.Int, reflect.Float64, reflect.Interface:\n    default:\n        return fmt.Errorf(\"unsupported kind %s\", v.Kind())\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"conf, err := getConfig(cfg)\nif err != nil {\n    var encErr error\n    if errors.As(err, &encErr) { log.Printf(\"revive config not encodable: %v\", encErr) }\n    // fall back to default revive config\n}","preventionTips":["Keep linters-settings.revive limited to documented shapes (rules with scalar arguments).","Keep golangci-lint and revive versions in sync.","Test config changes with `golangci-lint config verify` before CI.","Add complex revive settings incrementally to isolate failing values."],"tags":["golang","linter","revive","toml","configuration"],"backgroundTag":"config-encoding-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}