Textualize/textual · error · ActionError

unable to parse {action_args_str!r} in action {action!r}

Error message

unable to parse {action_args_str!r} in action {action!r}

What it means

ActionError raised when action argument strings cannot be parsed. Textual parses 'app.some_action(1, "x")' strings by wrapping args in parentheses and running ast.literal_eval; any syntax that literal_eval rejects triggers this error.

Source

Thrown at src/textual/actions.py:48

        action: String containing action.

    Raises:
        ActionError: If the action has invalid syntax.

    Returns:
        Action name and arguments.
    """
    args_match = re_action_args.match(action)
    if args_match is not None:
        action_name, action_args_str = args_match.groups()
        if action_args_str:
            try:
                # We wrap `action_args_str` to be able to disambiguate the cases where
                # the list of arguments is a comma-separated list of values from the
                # case where the argument is a single tuple.
                action_args: tuple[Any, ...] = ast.literal_eval(f"({action_args_str},)")
            except Exception:
                raise ActionError(
                    f"unable to parse {action_args_str!r} in action {action!r}"
                )
        else:
            action_args = ()
    else:
        action_name = action
        action_args = ()

    namespace, _, action_name = action_name.rpartition(".")

    return namespace, action_name, action_args

View on GitHub (pinned to 06dbeef4bb)

Solutions

  1. Quote string args explicitly in the action string: f"app.open({path!r})"
  2. Pass only literals (numbers, strings, tuples, booleans, None) — never variable names or calls
  3. Validate/escape user-supplied values before embedding them in action strings

Example fix

# before
action = f"app.open({filename})"  # bare name → literal_eval fails

# after
action = f"app.open({filename!r})"  # quoted string literal
Defensive patterns

Strategy: fallback

Validate before calling

import ast
def safe_action_args(argstr: str) -> bool:
    try:
        ast.literal_eval(f"({argstr},)")
        return True
    except Exception:
        return False

Try / catch

try:
    app.post_message(action)
except ActionError:
    # fall back to no-arg action or message-based dispatch
    app.post_message(action_name_only)

Prevention

When it happens

Trigger: Posting actions with malformed argument syntax, e.g. notify('app.tick(1,') , unbalanced quotes, name expressions, or f-string interpolated values that produce invalid literals.

Common situations: Building action strings dynamically from user input or f-strings that inject unquoted/broken values; actions defined in keybindings with typos.

Understand the failure class

Related errors


AI-assisted analysis of Textualize/textual@06dbeef4bb (2026-08-27). Data as JSON: /api/errors/1638229081441455. Report an issue: GitHub.