Skip to content

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

@marcospgp

Description

@marcospgp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions