mikefarah/yq · error

failed to read INI content: %w

Error message

failed to read INI content: %w

What it means

io.ReadAll failed while the INI decoder was draining its input reader inside Decode (Init only stores the reader). This wraps the underlying I/O error — the content was never parsed, so the problem is with the stream (closed reader, broken pipe, encoding issue), not with INI syntax.

Source

Thrown at pkg/yqlib/decoder_ini.go:41

}

func (dec *iniDecoder) Init(reader io.Reader) error {
	// Store the reader for use in Decode
	dec.reader = reader
	dec.finished = false
	return nil
}

func (dec *iniDecoder) Decode() (*CandidateNode, error) {
	// If processing is already finished, return io.EOF
	if dec.finished {
		return nil, io.EOF
	}

	// Read all content from the stored reader
	content, err := io.ReadAll(dec.reader)
	if err != nil {
		return nil, fmt.Errorf("failed to read INI content: %w", err)
	}

	// Parse the INI content
	loadOpts := ini.LoadOptions{
		PreserveSurroundedQuote: dec.prefs.PreserveSurroundedQuote,
	}
	cfg, err := ini.LoadSources(loadOpts, content)
	if err != nil {
		return nil, fmt.Errorf("failed to parse INI content: %w", err)
	}

	// Create a root CandidateNode as a MappingNode (since INI is key-value based)
	root := &CandidateNode{
		Kind:  MappingNode,
		Tag:   "!!map",
		Value: "",
	}

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Check the wrapped error for the real I/O cause (file truncated, reader closed early)
  2. Verify the input file exists and is readable before piping
  3. If reading from stdin, make sure the upstream process did not fail mid-stream
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at pkg/yqlib/decoder_ini.go:41 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05). Data as JSON: /api/errors/6a545c35ed24be9f. Report an issue: GitHub.