tomnomnom/gron · error

statement has no value

Error message

statement has no value

What it means

ungronTokens expects a statement whose second-to-last token is a value (the last token is always ';'). If the token before the trailing semicolon is not a value, the statement has no assigned value and ungronTokens returns "statement has no value".

Source

Thrown at ungron.go:374

// ungronTokens turns a slice of tokens into an actual datastructure
func ungronTokens(ts []token) (interface{}, error) {
	if len(ts) == 0 {
		return nil, errRecoverable{"empty input"}
	}

	if ts[0].typ == typIgnored {
		return nil, errRecoverable{"ignored token"}
	}

	if ts[len(ts)-1].typ == typError {
		return nil, errors.New("invalid statement")
	}

	// The last token should be typSemi so we need to check
	// the second to last token is a value rather than the
	// last one
	if len(ts) > 1 && !ts[len(ts)-2].isValue() {
		return nil, errors.New("statement has no value")
	}

	t := ts[0]
	switch {
	case t.isPunct():
		// Skip the token
		val, err := ungronTokens(ts[1:])
		if err != nil {
			return nil, err
		}
		return val, nil

	case t.isValue():
		var val interface{}
		d := json.NewDecoder(strings.NewReader(t.text))
		d.UseNumber()
		err := d.Decode(&val)
		if err != nil {

View on GitHub (pinned to 88a6234ea2)

Solutions

  1. Ensure every input line has a value between '=' and ';'
  2. Regenerate the input with `gron` instead of editing statement text
  3. Pre-validate lines with a regex like ^json.*= .+;$ before ungron

Example fix

// before
json.a =;   // no value

// after
json.a = null;
Defensive patterns

Strategy: validation

Validate before calling

re := regexp.MustCompile(`^\s*json.*=\s*[^;]+;\s*$`)
if !re.MatchString(line) {
	// line lacks a value; reject before ungron
}

Type guard

func statementHasValue(s statement) bool {
	return len(s) > 1 && s[len(s)-2].isValue()
}

Try / catch

v, err := ungronTokens(ts)
if err != nil {
	if err.Error() == "statement has no value" {
		// fix or skip the offending statement
	}
	return err
}

Prevention

When it happens

Trigger: `gron --ungron` on lines like `json.a =;` or `json.a;` — statements truncated so the '=' is immediately followed by ';', or the value token was dropped by prior text manipulation.

Common situations: Line-based editing (sed/awk/cut) that chopped off the value; diff/patch artifacts; manually constructed statements missing the RHS.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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