jesseduffield/lazygit · error
unable to parse filter regex, error: {{err}}
Error message
unable to parse filter regex, error: {{err}} What it means
MenuGenerator.getMenuItemFromLinefn compiles the `filter` field of a 'menuFromCommand' prompt as a Go regexp. If regexp.Compile fails (invalid regex syntax), this error wraps the underlying compile failure. The filter is applied to each line of the command output to extract menu entries.
Source
Thrown at pkg/gui/services/custom_commands/menu_generator.go:62
return nil, err
}
menuItems = append(menuItems, menuItem)
}
return menuItems, nil
}
func (self *MenuGenerator) getMenuItemFromLinefn(filter string, valueFormat string, labelFormat string) (func(line string) (*commandMenuItem, error), error) {
if filter == "" && valueFormat == "" && labelFormat == "" {
// showing command output lines as-is in suggestions panel
return func(line string) (*commandMenuItem, error) {
return &commandMenuItem{label: line, value: line}, nil
}, nil
}
regex, err := regexp.Compile(filter)
if err != nil {
return nil, errors.New("unable to parse filter regex, error: " + err.Error())
}
valueTemplateAux, err := template.New("format").Parse(valueFormat)
if err != nil {
return nil, errors.New("unable to parse value format, error: " + err.Error())
}
valueTemplate := NewTrimmerTemplate(valueTemplateAux)
var labelTemplate *TrimmerTemplate
if labelFormat != "" {
colorFuncMap := style.TemplateFuncMapAddColors(template.FuncMap{})
labelTemplateAux, err := template.New("format").Funcs(colorFuncMap).Parse(labelFormat)
if err != nil {
return nil, errors.New("unable to parse label format, error: " + err.Error())
}
labelTemplate = NewTrimmerTemplate(labelTemplateAux)
} else {
labelTemplate = valueTemplateView on GitHub (pinned to c477a2959b)
Solutions
- Fix the regex in the prompt's filter field to be valid RE2 syntax (drop lookaheads/backreferences, balance groups).
- Test the pattern with Go: `go run` a one-liner calling regexp.Compile, or use an RE2-compatible tester rather than a PCRE tester.
- If you meant a literal string, escape regex metacharacters or use a simpler pattern.
Example fix
# before
prompts:
- type: menuFromCommand
command: 'git branch'
filter: 'branch (?=origin)' # lookahead unsupported
# after
prompts:
- type: menuFromCommand
command: 'git branch'
filter: 'origin/.*' Defensive patterns
Strategy: validation
Validate before calling
// Validate the filter before shipping the config:
if _, err := regexp.Compile(prompt.Filter); err != nil {
return fmt.Errorf("bad filter for prompt %q: %w", prompt.Title, err)
} Prevention
- Test every menuFromCommand filter with Go's RE2 engine (PCRE-only constructs are unsupported).
- Prefer simple capture patterns over clever regexes in config files.
- Add a config lint step (regex + template compilation) to your dotfiles CI.
When it happens
Trigger: A menuFromCommand prompt whose filter string is not valid Go regexp syntax: unbalanced parentheses, invalid escapes like '\d{' unterminated, unsupported PCRE constructs (e.g. lookaheads '(?=...)' which Go's RE2 does not support).
Common situations: Copy-pasting a PCRE/JavaScript regex with lookaheads or backreferences into config.yml; forgetting that Go uses RE2; unescaped special characters in an intended literal filter.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unable to parse value format, error: {{err}}
- unable to parse label format, error: {{err}}
- custom command prompt must have a type of 'input', 'menu', '
- Unrecognized key '%s' for custom command. For permitted valu
- Error with custom command%s: it is not allowed to use both c
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/bac24c36c034a852.
Report an issue: GitHub.