Skip to content

Standalone tempest/console fails obscurely on required-argument validation when tempest/event-bus is missing #2192

Description

@marccoup

Tempest version

3.0

PHP version

8.5

Operating system

macOS

Description

When building a standalone console app with only tempest/console (as documented in the console package docs), commands with required parameters can fail in a non-obvious way during normal interactive use.

If a required argument is omitted, Tempest correctly prompts for it. The failure happens when the user submits invalid input (e.g. pressing Enter on an empty value). Tempest then tries to render a validation error message and throws:

× // Tempest\Validation\Exceptions\TranslatorWasRequired
× // A translator instance is required to generate validation error messages, but none was provided.

This is surprising because:

  • Required parameters are extremely common: most real commands have at least one required argument, so you can hit this almost immediately after setting up (this is what happened to me!)
  • The standalone setup docs do not mention this dependency: following them alone is enough to hit the failure.
  • The failure is obscured: the prompt appears and looks fine; the crash only happens on validation failure, and the exception points at Validator / translation, not at a missing package or incomplete setup.
  • The root cause is indirect: tempest/console pulls in tempest/validation which in turn pulls in tempest/intl, but TranslatorInitializer resolves EventBus, and tempest/event-bus is not installed by a minimal standalone setup. Validator accepts an optional ?Translator and silently gets null when translation cannot be constructed, so the app boots until validation needs a message.

Steps to reproduce

  1. Create a minimal standalone console app as documented in the console package docs
  2. Define a simple command with a required argument:
#[ConsoleCommand(name: 'foo')]
public function __invoke(string $bar): ExitCode {
    return ExitCode::SUCCESS;
}
  1. Run without the argument in an interactive TTY:
./my-cli example:run
  1. At the prompt, press Enter without typing a value.

Expected behaviour

Either:

  1. Validation fails with a clear, user-facing message (e.g. “must not be empty”), or
  2. Setup fails early with documentation or an error that makes the missing dependency obvious.

Actual behaviour

TranslatorWasRequired is thrown from Validator::getErrorMessage().

Environment

  • PHP 8.5
  • tempest/console ^3.13
  • Minimal install: tempest/console only (no tempest/event-bus)

Why (I think) this matters

Required arguments are a super common pattern for CLI commands. A developer following the standalone console docs, defining a normal command, and testing it interactively can easily hit this without any indication that tempest/event-bus is needed. The error reads like an internal framework bug rather than a setup gap.

Suggested directions

I see two reasonable fixes; happy to open a PR for whichever you as maintainers prefer:

Option 1 - Documentation

Update the standalone console docs to note that interactive prompts with validation (including automatic prompting for missing required arguments) need a working Translator, which currently requires installing tempest/event-bus, the whole fix just being to run:

composer require tempest/event-bus

Document the symptom (TranslatorWasRequired) so users can connect it to the missing dependency.

Option 2 - Package dependency

Add tempest/event-bus as a direct requirement of tempest/console so standalone console apps work out of the box for the common case of required parameters and interactive validation, without an extra install step.

Option 1 is the smallest change; Option 2 gives the better DX for the most common standalone use case. I think that either would be a big improvement over the current behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions