tomnomnom/gron · error

unexpected token `%s`

Error message

unexpected token `%s`

What it means

ungronTokens hit a token whose type matches none of its known cases (bare key, quoted key, numeric key, or value token), so the token stream is not a parseable assignment statement. The default branch is a generic guard against malformed or unexpected token streams.

Source

Thrown at ungron.go:438

	case t.typ == typNumericKey:
		key, err := strconv.Atoi(t.text)
		if err != nil {
			return nil, fmt.Errorf("invalid integer key `%s`", t.text)
		}

		val, err := ungronTokens(ts[1:])
		if err != nil {
			return nil, err
		}

		// There needs to be at least key + 1 space in the array
		out := make([]interface{}, key+1)
		out[key] = val
		return out, nil

	default:
		return nil, fmt.Errorf("unexpected token `%s`", t.text)
	}
}

// recursiveMerge merges maps and slices, or returns b for scalars
func recursiveMerge(a, b interface{}) (interface{}, error) {
	switch a.(type) {

	case map[string]interface{}:
		bMap, ok := b.(map[string]interface{})
		if !ok {
			return nil, fmt.Errorf("cannot merge object with non-object")
		}
		return recursiveMapMerge(a.(map[string]interface{}), bMap)

	case []interface{}:
		bSlice, ok := b.([]interface{})
		if !ok {
			return nil, fmt.Errorf("cannot merge array with non-array")

View on GitHub (pinned to 88a6234ea2)

Solutions

  1. Correct the input grammar so the token stream only contains valid assignment tokens
  2. Check whether the token came from truncated input such as a statement missing the '=' and value part
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at ungron.go:438 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of tomnomnom/gron@88a6234ea2 (2026-09-06). Data as JSON: /api/errors/fdc77db77d40e720. Report an issue: GitHub.