golangci/golangci-lint · error
YAML decode file %s: %w
Error message
YAML decode file %s: %w
What it means
parser.Decode wraps errors from yaml.NewDecoder(file).Decode(data) when a .yaml/.yml/.json configuration file cannot be parsed into the data map. An io.EOF (empty file) is intentionally tolerated. This means the config file is syntactically invalid YAML or JSON.
Source
Thrown at pkg/commands/internal/migrate/parser/parser.go:30
"github.com/pelletier/go-toml/v2"
"go.yaml.in/yaml/v3"
)
type File interface {
io.ReadWriter
Name() string
}
// Decode decodes a file into data.
// The choice of the decoder is based on the file extension.
func Decode(file File, data any) error {
ext := filepath.Ext(file.Name())
switch strings.ToLower(ext) {
case ".yaml", ".yml", ".json":
err := yaml.NewDecoder(file).Decode(data)
if err != nil && !errors.Is(err, io.EOF) {
return fmt.Errorf("YAML decode file %s: %w", file.Name(), err)
}
case ".toml":
err := toml.NewDecoder(file).Decode(&data)
if err != nil {
return fmt.Errorf("TOML decode file %s: %w", file.Name(), err)
}
default:
return fmt.Errorf("unsupported file type: %s", ext)
}
return nil
}
// Encode encodes data into a file.
// The choice of the encoder is based on the file extension.
func Encode(data any, dstFile File) error {View on GitHub (pinned to ed7a235d2d)
Solutions
- Open the file at the reported line/column and fix the YAML/JSON syntax error (replace tabs with spaces, fix indentation).
- Validate the file with `yamllint <file>` or paste it into a YAML validator.
- Remove any Git merge-conflict markers left in the config.
- Restore the file from version control if it is truncated or corrupted.
Example fix
// before (.golangci.yml — tab indentation)
linters:
enable:
- gocritic
// after
linters:
enable:
- gocritic Defensive patterns
Strategy: validation
Validate before calling
data, err := os.ReadFile(cfgPath)
if err != nil { return err }
if bytes.ContainsRune(data, '\t') { return errors.New("tabs are invalid YAML indentation") }
if bytes.Contains(data, []byte("<<<<<<<")) { return errors.New("merge conflict markers present") } Try / catch
if err := parser.Decode(f, &data); err != nil {
var yerr *yaml.TypeError
if errors.As(err, &yerr) { /* show line/type info */ }
if errors.Is(err, io.EOF) { /* treat as empty config */ }
return err
} Prevention
- Configure the editor to use spaces, never tabs, in YAML.
- Validate YAML/JSON with yamllint or a linter before committing.
- Resolve merge conflicts in config files completely.
- Keep config files under version control to restore corrupted copies.
When it happens
Trigger: Calling Decode on a file whose extension is .yaml/.yml/.json and whose content fails YAML/JSON parsing — bad indentation, tabs in YAML, unclosed quotes/brackets, duplicate keys, or invalid JSON syntax.
Common situations: Hand-edited .golangci.yml with tab characters or inconsistent indentation, merge-conflict markers (<<<<<<<) left in the file, or a truncated file from a failed write.
Related errors
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/552a2314fe346db5.
Report an issue: GitHub.