[BUG]: `drizzle-kit pull` fails with a confusing error if the database can't be reached
Report hasn't been filed before.
- I have verified that the bug I'm about to report hasn't been filed before.
What version of drizzle-orm are you using?
1.0.0-rc.4
What version of drizzle-kit are you using?
1.0.0-rc.4
Other packages
No response
Describe the Bug
When running drizzle-kit pull, if the database isn't accessible at the address supplied, it fails with the following error:
No config path provided, using default 'drizzle.config.ts'
Reading config file '/.../drizzle.config.ts'
Using 'pg' driver for database querying
[⣷] 0 tables fetching
[⣷] 0 columns fetching
[⣷] 0 enums fetching
[⣷] 0 indexes fetching
[⣷] 0 foreign keys fetching
[⣷] 0 policies fetching
[⣷] 0 check constraints fetching
[⣷] 0 views fetching
[✗] Error during introspection:
Error
at /.../node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:150258:12
at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
at async Object.query (/.../node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:150253:13)
at async Promise.all (index 0)
at async fromDatabase$3 (/.../node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:153920:56)
at async fromDatabaseForDrizzle$3 (/.../node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:154640:15)This makes it hard to debug what the issue is (in my case, the port in my connection string was incorrect).
In fact, I had to temporarily edit the bin.cjs to add a console.log before a throw clause because it seems the error being thrown is not being logged.
const query = async (sql, params) => {
return (await pool.query({
text: sql,
values: params ?? [],
types
}).catch((e) => {
+ console.log(e)
throw new QueryError(e, sql, params || []);
})).rows;
}This revealed the real issue: ECONNREFUSED
I think this error is happening somewhere around here in the codebase if it helps: https://github.com/drizzle-team/drizzle-orm/blob/15454dbe49d827c6081f3d0231e2e7985e517295/drizzle-kit/src/cli/connections.ts#L230-L237
The ideal solution is that drizzle-kit logs these errors out instead of (or alongside) the stack trace.
Source: drizzle-team/drizzle-orm