bettercap/bettercap · error

expression '%s' doesn't parse

Error message

expression '%s' doesn't parse

What it means

ViewSelector.parseSorting reads the module's sort parameter (e.g. `sort.field asc`) and tokenizes it with a regex. If the whole expression matches no token, the selector cannot determine a sort field/direction and returns this error. It guards every view that supports sortable output.

Source

Thrown at modules/utils/view_selector.go:85

				return
			}
		}
	} else {
		s.Expression = nil
	}
	s.filterPrev = s.Filter
	return
}

func (s *ViewSelector) parseSorting() (err error) {
	expr := ""
	if err, expr = s.owner.StringParam(s.sortName); err != nil {
		return
	}

	tokens := s.sortParse.FindAllStringSubmatch(expr, -1)
	if tokens == nil {
		return fmt.Errorf("expression '%s' doesn't parse", expr)
	}

	s.SortField = tokens[0][1]
	s.Sort = tokens[0][2]
	s.SortSymbol = tui.Blue("▾")
	if s.Sort == "asc" {
		s.SortSymbol = tui.Blue("▴")
	}

	return
}

func (s *ViewSelector) Update() (err error) {
	if err = s.parseFilter(); err != nil {
		return
	} else if err = s.parseSorting(); err != nil {
		return
	} else if err, s.Limit = s.owner.IntParam(s.limitName); err != nil {

View on GitHub (pinned to 8eca2820f3)

Solutions

  1. Set the sort parameter to `<field> <asc>` or `<field> <desc>` with a single space.
  2. Check the module's documentation for the exact accepted field name for that view.
  3. Reset the parameter to its documented default.

Example fix

// before
set wifi.recon.sort = stations
// after
set wifi.recon.sort = "stations asc"
Defensive patterns

Strategy: validation

Validate before calling

const sortExpr = params['sort'] ?? ''
if (sortExpr !== '' && !/^[a-zA-Z0-9_.-]+\s+(asc|desc)$/.test(sortExpr.trim())) {
  throw new Error(`sort must look like '<field> asc|desc', got: '${sortExpr}'`)
}

Type guard

function isValidSortExpr(s) { return /^[a-zA-Z0-9_.-]+\s+(asc|desc)$/.test(s.trim()) }

Try / catch

try {
  selector.Update()
} catch (e) {
  if (String(e).includes("doesn't parse")) {
    console.error('Bad sort expression; expected "<field> asc|desc"')
  } else { throw e }
}

Prevention

When it happens

Trigger: Setting a module's `sort` parameter (via ViewSelectorFor/Update) to a string that does not match the `<field> <asc|desc>` pattern, or to an empty/unsettable value that yields no regex matches.

Common situations: Typing `sort.field=asc` (with '='), omitting the direction, misspelling `asc`/`desc`, or a parameter template that expands to an empty string.

Related errors


AI-assisted analysis of bettercap/bettercap@8eca2820f3 (2026-09-02). Data as JSON: /api/errors/356f17b876084038. Report an issue: GitHub.