Skip to content

Clearer errors for frozen services - #371

Merged
techmahedy merged 2 commits into
doppar:4.xfrom
techmahedy:issue-4.x
Oct 17, 2026
Merged

techmahedy merged 2 commits into
doppar:4.xfrom
techmahedy:issue-4.x

Conversation

@techmahedy

Copy link
Copy Markdown
Member

Clearer errors for frozen services

Summary

The ImmutableViolationException messages were out of date and, for clone, confusing. This PR fixes the wording so the message matches how frozen services work today and tells the developer what to do.

The problems

  1. The message described the old behavior. It said services are "frozen after instantiation". Since the previous PR, a service is frozen the first time the container resolves it, so the message was no longer accurate.
  2. No hint about the fix. The docs showed a third line telling the reader to configure the service in a launcher during boot. The code never produced that line, so the docs promised more than the framework printed. The same docs line also said "ServiceProvider", which is the wrong word in 4.x (launchers replaced service providers).
  3. Clone had a strange message. Cloning a frozen service threw Cannot mutate property $__clone on immutable service [...]. There is no property called $__clone, so the message pointed the reader in the wrong direction.

What changed

Mutation (write, dynamic property, unset()):

Cannot mutate property $taxRate on immutable service [App\Services\PaymentService].
Services marked #[Immutable] are frozen once the container resolves them.
Configure the service in a launcher during boot, before it is first resolved, not at runtime.

Clone:

Cannot clone immutable service [App\Services\PaymentService].
Services marked #[Immutable] are frozen once the container resolves them, and a clone would be a way around that.
Resolve the service from the container instead.
  • Only ImmutableViolationException changed. Its constructor signature is the same, and the exception is thrown from the same places.
  • The test testFreezeIsIdempotent now calls freeze() twice for real. It had the second call commented out, from before freeze() was safe to repeat.

@techmahedy techmahedy added the bug Something isn't working label Oct 17, 2026
@techmahedy
techmahedy merged commit a370047 into doppar:4.x Oct 17, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant