inancgumus/learngo · error

Wrong operation: '<op>'

Error message

Wrong operation: '<op>'

What it means

Do() returns this error when the op argument does not match any of the supported operators: +/plus, -/minus, */times, //div, %/mod. The switch's default branch rejects unknown or misspelled operation strings coming from the command line.

Source

Thrown at x-tba/foundations/calc/09-packages/calc/calc.go:41

// Do ...
func Do(a, b float64, op string) (res float64, err error) {
	switch op {
	case "+", "plus":
		op, res = "+", a+b
	case "-", "minus":
		op, res = "-", a-b
	case "*", "times":
		op, res = "*", a*b
	case "/", "div":
		op, res = "/", a/b
	case "%", "mod":
		res = float64(int(a) % int(b))
	default:
		return 0, errors.New("Wrong operation: '" + op + "'")
	}
	return
}

View on GitHub (pinned to 3c475a78e5)

Solutions

  1. Print the supported operator list (+, -, *, /, %) and their word aliases, then exit with a non-zero status.
  2. Validate the op argument before calling calc.Do (e.g., in main when parsing flags).
  3. Normalize user input (lowercase, trim) so aliases like "PLUS" map to the accepted forms.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at x-tba/foundations/calc/09-packages/calc/calc.go:41 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of inancgumus/learngo@3c475a78e5 (2026-09-02). Data as JSON: /api/errors/da7283458615f736. Report an issue: GitHub.