golangci/golangci-lint · error
unknown type %s
Error message
unknown type %s
What it means
goconst's toType maps user-facing string values (from config) to goconst API option types; an unrecognized string falls to the default branch and yields 'unknown type %s'. The config value for which option it applies to (e.g. match-constant vs number-minimum occurrences category or occurrence type) is not one of the accepted literals.
Source
Thrown at pkg/golinters/goconst/goconst.go:150
return goconstAPI.Assignment, nil
case "binary":
return goconstAPI.Binary, nil
case "case":
return goconstAPI.Case, nil
case "return":
return goconstAPI.Return, nil
case "call":
return goconstAPI.Call, nil
case "compositelit":
return goconstAPI.CompositeLit, nil
default:
return 0, fmt.Errorf("unknown type %s", v)
}
}
View on GitHub (pinned to ed7a235d2d)
Solutions
- Check the goconst settings documentation and use exact accepted values (e.g. 'compositelit', not 'compositeliteral')
- Fix casing/typos — values are compared as raw strings
- Remove the invalid option to fall back to defaults
- Upgrade/downgrade golangci-lint if the valid value set changed between versions
Example fix
# before
linters-settings:
goconst:
ignore-type: compositeliteral
# after
linters-settings:
goconst:
ignore-type: compositelit Defensive patterns
Strategy: validation
Validate before calling
validGoconstValues := map[string]bool{"string": true, "number": true, "compositelit": true}
for _, v := range goconstTypeValues {
if !validGoconstValues[strings.ToLower(v)] {
return fmt.Errorf("invalid goconst type value %q; allowed: string|number|compositelit", v)
}
} Try / catch
if err := golangci.Run(); err != nil {
if strings.Contains(err.Error(), "unknown type") {
fmt.Fprintln(os.Stderr, "fix goconst setting value: must be one of the documented literals (e.g. compositelit)")
os.Exit(1)
}
return err
} Prevention
- Copy goconst option values from the official docs, not from memory
- Keep values lowercase and exact (compositelit, not compositeliteral)
- Lint the YAML config in CI with a schema check (e.g. golangci-lint config verify)
When it happens
Trigger: runGoconst read a goconst setting (e.g. the type/occurrence-related option such as 'find-duplicates' or the string-vs-compositelit selector) whose value isn't 'string' equivalent, 'number', or 'compositelit', so the switch in toType hits default.
Common situations: Typo in .golangci.yml (e.g. 'compositeliteral', 'CompositLit', 'str'), copying an option name from a newer/older goconst version with renamed values, or YAML quoting introducing unexpected characters.
Related errors
- can't combine option --config and --no-config
- can't get enabled formatters: %w
- failed to set analyzer setting %q with value %q: %w
- settings key %q must be valid analyzer name, valid analyzers
- failed to configure analyzer %s: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/5671f0f0afc845a1.
Report an issue: GitHub.