[BUG]: drizzle-kit swallows stack traces on schema-load errors, printing only the message

Open Beginner friendly
#5,880 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
nodejs, typescript
Domain
cli

Research direction

Start in src/cli/index.ts at the unknown_error theme handler described in the issue, then reproduce the failure with the provided schema and drizzle.config.ts using drizzle-kit generate. Confirm the completed behavior by checking that schema-loading errors include their stack traces for generate, migrate, push, and other schema-loading commands.

Written by the indexing model from the issue text.

Description

What version of drizzle-orm are you using?

1.0.0-rc.3

What version of drizzle-kit are you using?

1.0.0-rc.3

Other packages

No response

Describe the Bug

When a schema file throws during module evaluation, drizzle-kit generate prints only the error message and exits. The stack trace is discarded, so there is no indication of which file or line crashed.

Repro: point the config at a schema file that throws while loading.

// schema.ts
import { pgTable, text } from "drizzle-orm/pg-core";

const broken: { kind: string } | undefined = undefined;
console.log(broken!.kind); // stand-in for any eval-time crash

export const users = pgTable("users", { id: text("id") });
// drizzle.config.ts
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "postgresql",
  schema: "./schema.ts",
  out: "./migrations",
});
$ drizzle-kit generate
Reading config file 'drizzle.config.ts'
Error  Cannot read properties of undefined (reading 'kind')

That single line is the entire output. In a real project the schema spans dozens of files, and an eval-time crash (ours came from a circular import that left a table half-initialized) gives you nothing to go on. We ended up patching bin.cjs to recover the stack:

Error  Cannot read properties of undefined (reading 'kind')
TypeError: Cannot read properties of undefined (reading 'kind')
    at /path/to/server/schema.ts:5:20
    at async Function.import (node_modules/drizzle-kit/bin.cjs:38495:17)
    at async prepareFromSchemaFiles$5 (node_modules/drizzle-kit/bin.cjs:89621:35)
    ...

The swallow happens in the CLI's unknown_error theme handler (src/cli/index.ts), which logs e.message and returns. Printing e.stack there (or behind a --verbose flag) would make schema-loading crashes debuggable.

The same applies to migrate, push, and any other command that loads schema files.

Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
1d 13h
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from drizzle-team/drizzle-orm

All issues in drizzle-team/drizzle-orm

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.