Fix #50: point DriverNotFoundException at the right cause - #99
Open
corgab wants to merge 2 commits into
Open
Conversation
The message always told the developer to check 'aether.default', even
when the unknown name was passed explicitly to Quantum::driver('ionq') or
Quantum::circuit('ionq'), which is the common case during development and
has nothing to do with that setting. Manager resolves a null argument to
the default before createDriver() runs, so an unknown name that equals the
default now blames the aether.default setting, and any other unknown name
points at Quantum::extend() and a possible typo, naming the built-in
drivers.
Closes #50
Comparing the unknown name with getDefaultDriver() exposed two latent
faults: a null aether.default returned null from a string-typed method,
and a blank one made Str::studly('') resolve to createDriver itself. The
default now falls back to 'local' for null or blank values, and an empty
name can no longer match a method. Enum-backed driver arguments arrive as
their raw value, so createDriver() casts once before matching creators or
building the message. The explicit-name message lists the drivers that do
resolve, built-ins and extend()ed ones alike, from the manager instead of
a hard-coded pair.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DriverNotFoundException::forDriver()always said "Check your 'aether.default' configuration", butQuantumManager::createDriver()is reached both when the default driver is resolved and when a caller names a driver explicitly (Quantum::driver('ionq'),Quantum::circuit('ionq')). The explicit case is the common one during development, a typo or a custom driver that was never registered, and the message sent the developer to a setting they had not touched.Plan
Distinguish the two cases where the information exists.
Illuminate\Support\Manager::driver()resolves a null argument togetDefaultDriver()before callingcreateDriver($name), so insidecreateDriver()an unknown name that equals the configured default is a configuration problem, and any other unknown name was requested explicitly. Make the explicit message useful by listing the names that do resolve, taken from the manager rather than hard-coded.Changes
DriverNotFoundException::forDriver(string $name, array $available = []): lists the registered drivers when given, suggestsQuantum::extend('<name>', ...)and a possible typo; no longer mentionsaether.default.DriverNotFoundException::forDefaultDriver(string $name)(new): says the driver is configured as the default and points ataether.default/AETHER_DRIVER, or atQuantum::extend().QuantumManager::createDriver(): casts the argument once (an int-backed enum arrives as its raw value), refuses to match an empty name againstcreateDriveritself, and picks the factory by comparing withgetDefaultDriver(), passing the built-in plusextend()ed names for the explicit case.QuantumManager::getDefaultDriver(): anullor blankaether.default(an emptyAETHER_DRIVER=line) falls back tolocalinstead of surfacing as aTypeErroror anArgumentCountError.No config change, no new dependencies, same exception class in both cases so existing
catchblocks are unaffected.Tests
ExceptionHierarchyTest:forDriver()mentions the name and theextend()hint and notaether.default, and lists the registered drivers when given;forDefaultDriver()mentionsaether.defaultandAETHER_DRIVER.QuantumManagerTest: an explicit unknown driver with a valid default blames the name, not the setting; an unknown default blames the setting; the message names anextend()ed driver; anullor blank default resolves to the local driver; an unknown explicit driver with anulldefault still throwsDriverNotFoundException.Local: pint passed, pest 799 tests passed.
Closes #50