getsops/sops · error

Could not unmarshal input data: %s

Error message

Could not unmarshal input data: %s

What it means

LoadPlainFile parses plaintext INI bytes with gopkg.in/ini.v1 (treeBranchesFromIni). When ini.LoadSources returns a parse error — malformed syntax, unterminated sections, bad quoting, or invalid structure — this wrapper reports the input could not be unmarshaled, including the underlying parser message.

Source

Thrown at stores/ini/store.go:157

	}
	branches, metadata, err := stores.ExtractMetadata(branches, stores.MetadataOpts{
		Flatten:        stores.MetadataFlattenBelowTop,
		EscapeNewlines: true,
	})
	if err != nil {
		return sops.Tree{}, err
	}
	return sops.Tree{
		Branches: branches,
		Metadata: metadata,
	}, nil
}

// LoadPlainFile loads a plaintext INI file's bytes onto a sops.TreeBranches runtime object
func (store *Store) LoadPlainFile(in []byte) (sops.TreeBranches, error) {
	branches, err := store.treeBranchesFromIni(in)
	if err != nil {
		return branches, fmt.Errorf("Could not unmarshal input data: %s", err)
	}
	return branches, nil
}

// EmitEncryptedFile returns encrypted INI file bytes corresponding to a sops.Tree
// runtime object
func (store *Store) EmitEncryptedFile(in sops.Tree) ([]byte, error) {
	branches, err := stores.SerializeMetadata(in, stores.MetadataOpts{
		Flatten:        stores.MetadataFlattenBelowTop,
		EscapeNewlines: true,
	})
	if err != nil {
		return nil, fmt.Errorf("Error marshaling metadata: %s", err)
	}
	return store.EmitPlainFile(branches)
}

// EmitPlainFile returns the plaintext INI file bytes corresponding to a sops.TreeBranches object

View on GitHub (pinned to 13442bb981)

Solutions

  1. Read the wrapped ini.v1 error (it includes line numbers) and fix the syntax at that line in the input file
  2. Verify the file is actually INI (sections like [name], key=value lines), not YAML/JSON
  3. Re-encode the file as UTF-8/ASCII and ensure it is not truncated or binary-corrupted
  4. Restore the file from version control or a backup if it was hand-edited badly

Example fix

// before (broken INI)
=missingkey

// after
key=value
Defensive patterns

Strategy: try-catch

Validate before calling

func looksLikeIni(data []byte) bool {
	for _, line := range strings.Split(string(data), "\n") {
		l := strings.TrimSpace(line)
		if l == "" || strings.HasPrefix(l, ";") || strings.HasPrefix(l, "#") || strings.HasPrefix(l, "[") {
			continue
		}
		if !strings.Contains(l, "=") {
			return false
		}
	}
	return true
}

Try / catch

branches, err := store.LoadPlainFile(data)
if err != nil {
	var parseErr error
	if strings.Contains(err.Error(), "Could not unmarshal input data") {
		return fmt.Errorf("input is not valid INI; check the line noted in: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling LoadPlainFile or LoadEncryptedFile on bytes that are not valid INI: e.g. a line like "=value" with an empty key, or "[[bad" section syntax, or binary/truncated data.

Common situations: Editing an encrypted sops INI file by hand and breaking syntax; passing a YAML or JSON file with the --ini flag; a pipe/CI step that truncated or corrupted the file; wrong file encoding (UTF-16) that the parser cannot read.

Related errors


AI-assisted analysis of getsops/sops@13442bb981 (2026-09-01). Data as JSON: /api/errors/7d952e89f28c11ab. Report an issue: GitHub.