go-delve/delve · error

syntax error '=' not found

Error message

syntax error '=' not found

What it means

The 'set' command emulates assignment by parsing the input with go/parser (since '=' is not valid Go expression syntax at top level) and rewriting it into a comparison-detected error. If the input parses cleanly as an expression there is no '=' at all — meaning the user forgot 'variable = value' — and Delve reports this error. If the parse error is not the expected "expected '==', found '='", the original parse error is returned instead.

Source

Thrown at pkg/terminal/command.go:2258

		fmt.Fprintln(t.stdout, val.Type)
	}
	if val.RealType != val.Type {
		fmt.Fprintf(t.stdout, "Real type: %s\n", val.RealType)
	}
	if val.Kind == reflect.Interface && len(val.Children) > 0 {
		fmt.Fprintf(t.stdout, "Concrete type: %s\n", val.Children[0].Type)
	}
	if t.conf.ShowLocationExpr && val.LocationExpr != "" {
		fmt.Fprintf(t.stdout, "location: %s\n", val.LocationExpr)
	}
	return nil
}

func setVar(t *Term, ctx callContext, args string) error {
	// HACK: in go '=' is not an operator, we detect the error and try to recover from it by splitting the input string
	_, err := parser.ParseExpr(args)
	if err == nil {
		return errors.New("syntax error '=' not found")
	}

	el, ok := err.(scanner.ErrorList)
	if !ok || el[0].Msg != "expected '==', found '='" {
		return err
	}

	lexpr := args[:el[0].Pos.Offset]
	rexpr := args[el[0].Pos.Offset+1:]
	return t.client.SetVariable(ctx.Scope, lexpr, rexpr)
}

func (t *Term) printFilteredVariables(varType string, vars []api.Variable, filter string, cfg api.LoadConfig) error {
	reg, err := regexp.Compile(filter)
	if err != nil {
		return err
	}
	match := false

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Use full assignment syntax: 'set myVar = <value>'.
  2. Do not omit the '=' sign; 'set x 5' is invalid, 'set x = 5' is correct.
  3. If the value itself fails to parse, note the returned error would be the go/parser error rather than this message.

Example fix

// before
(dlv) set myCounter 5
// after
(dlv) set myCounter = 5
Defensive patterns

Strategy: validation

Validate before calling

func validateSetArgs(args string) error {
    if !strings.Contains(args, "=") {
        return fmt.Errorf("set requires 'lhs = rhs', got %q", args)
    }
    return nil
}

Try / catch

if err := cmd.SetVar(term, ctx, args); err != nil {
    if err.Error() == "syntax error '=' not found" {
        return fmt.Errorf("missing '=' in set command: %q", args)
    }
    return err
}

Prevention

When it happens

Trigger: Running 'set myVar' (no '= value' part) so parser.ParseExpr succeeds with no assignment, in setVar (pkg/terminal/command.go). Also 'set a b' with no '=' triggers it.

Common situations: Users typing just the variable name expecting a prompt, or writing whitespace-separated assignment like 'set x 5' instead of 'set x = 5'.

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/eab68da1cb221d0d. Report an issue: GitHub.