Skip to content

fix: validate stream name in createStream/updateStream - #82

Open
klezaic wants to merge 2 commits into
mainfrom
fix/validate-stream-name
Open

klezaic wants to merge 2 commits into
mainfrom
fix/validate-stream-name

Conversation

@klezaic

@klezaic klezaic commented Apr 23, 2026

Copy link
Copy Markdown

Summary

  • Reject invalid stream names up front in JetStreamContext::createStream and
    updateStream with a clear \InvalidArgumentException naming the offending
    value, instead of letting the request time out waiting for a reply that will
    never come.
  • Rules mirror NATS server validation: non-empty, and no whitespace, ., *,
    >, /, \, or control characters.
  • createOrUpdateStream picks up the guard transitively.

Why

A bad character in the stream name produced
Sofascore\Nats\TimeoutException: Subscription nextMessage timed out, which
gave no signal that the caller's input was the problem. Fixing this at the
boundary turns a hard-to-diagnose timeout into an actionable error.

Fixes #81

Test plan

  • vendor/bin/phpunit --testsuite=unit passes (includes the new
    JetStreamContextStreamNameValidationTest covering each forbidden char
    class plus empty input and 6 valid shapes).
  • vendor/bin/phpstan analyse --no-progress clean.
  • vendor/bin/php-cs-fixer fix --dry-run --diff clean.
  • Manual: calling createStream(new StreamConfig(name: 'bad.name')) now
    throws \InvalidArgumentException immediately instead of timing out.

@klezaic
klezaic requested a review from matkomat April 23, 2026 09:25
@klezaic klezaic self-assigned this Apr 23, 2026
@klezaic klezaic added enhancement New feature or request good first issue Good for newcomers area:jetstream JetStream streams, consumers, and publishing labels Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:jetstream JetStream streams, consumers, and publishing enhancement New feature or request good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createStream/updateStream surface misleading timeout when stream name contains invalid characters

1 participant