Skip to content

Commit 4dba9bf

Browse files
committed
fix(drivers): name a location when the missing-driver error searched nothing
Drivers are deliberately not shipped, so "driver not installed" is a normal state users hit by design rather than an edge case. `driverSearchRoots()` returns only directories that exist, so on a machine that has never installed a driver it returns nothing and the error ended in a bare "Searched 0 locations:" — a colon with nothing after it, naming nowhere to look. Say plainly that there was nothing to search, and name the `node_modules` directory the printed install command creates. Resolution behaviour is unchanged; this is the error text and one branch. Two tests: the empty case must not render "Searched 0 locations:" and must name the install directory, and the populated case must still list the roots it actually searched.
1 parent 7b4373f commit 4dba9bf

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎packages/drivers/src/resolve.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,21 @@ export class DriverNotInstalledError extends Error {
9090

9191
constructor(driver: DriverName, packages: readonly string[], searched: readonly string[]) {
9292
const label = DRIVER_LABELS[driver]
93+
const installDir = driverInstallDir()
94+
// `driverSearchRoots()` only returns directories that exist, so on a machine
95+
// that has never installed a driver it returns nothing at all — the normal
96+
// first-run state, given drivers are deliberately not shipped. That left the
97+
// message ending in a bare "Searched 0 locations:" with nothing after the
98+
// colon, which names nowhere and reads like a bug. Say plainly that there was
99+
// nothing to search, and name the directory the install command creates.
100+
const searchedLine = searched.length
101+
? `Searched ${searched.length} location${searched.length === 1 ? "" : "s"}: ${searched.join(", ")}`
102+
: `Searched nothing: no driver directory exists yet, not even ${path.join(installDir, "node_modules")}.`
93103
super(
94104
`${label} driver not installed.\n` +
95105
`Install it with the warehouse_install_driver tool, or run:\n` +
96-
` npm install --prefix ${shellQuote(driverInstallDir())} ${packages.join(" ")}\n` +
97-
`Searched ${searched.length} location${searched.length === 1 ? "" : "s"}: ${searched.join(", ")}`,
106+
` npm install --prefix ${shellQuote(installDir)} ${packages.join(" ")}\n` +
107+
searchedLine,
98108
)
99109
this.name = "DriverNotInstalledError"
100110
this.driver = driver

‎packages/drivers/test/resolve-unit.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,31 @@ describe("manual-install hints are copy-pasteable", () => {
608608
expect(prefix!.startsWith("'") || prefix!.startsWith('"')).toBe(true)
609609
})
610610

611+
test("DriverNotInstalledError names a location when nothing was searched", () => {
612+
process.env["ALTIMATE_DRIVER_DIR"] = path.join(path.sep, "tmp", "altimate-drivers-absent")
613+
614+
// The first-run state: no driver directory exists, so driverSearchRoots()
615+
// returns nothing. The message must still name somewhere.
616+
const err = new DriverNotInstalledError("duckdb", DRIVER_PACKAGES.duckdb, [])
617+
618+
expect(err.message).not.toContain("Searched 0 locations:")
619+
expect(err.message).toContain("Searched nothing")
620+
expect(err.message).toContain(path.join("altimate-drivers-absent", "node_modules"))
621+
// Still distinguishable from a broken install, and still actionable.
622+
expect(err.message).toContain("DuckDB driver not installed.")
623+
expect(err.message).toContain("npm install --prefix")
624+
})
625+
626+
test("DriverNotInstalledError lists the roots it did search", () => {
627+
const roots = [path.join(path.sep, "a", "node_modules"), path.join(path.sep, "b", "node_modules")]
628+
629+
const err = new DriverNotInstalledError("duckdb", DRIVER_PACKAGES.duckdb, roots)
630+
631+
expect(err.message).toContain("Searched 2 locations:")
632+
for (const root of roots) expect(err.message).toContain(root)
633+
expect(err.message).not.toContain("Searched nothing")
634+
})
635+
611636
test("no source builds a --prefix hint without shellQuote", () => {
612637
// Structural, because the behavioural tests can only cover the sites someone
613638
// remembered to write a case for. This fails when a NEW unquoted hint is

0 commit comments

Comments
 (0)