graphile / migrate

Opinionated SQL-powered productive roll-forward migration tool for PostgreSQL.
MIT License
751 stars 58 forks source link

SQL errors lost in Javascript stacktrace #99

Open brendanmckenzie opened 4 years ago

brendanmckenzie commented 4 years ago

Feature description

When running migrate watch in a rather short terminal window SQL errors are lost amongst Javascript stack traces

Motivating example

There are 10 lines of JS stack trace for 2 lines of SQL errors.

graphile-migrate: Already up to date
[2020-11-04T06:48:27.687Z]: Running current.sql

🛑 Error occurred at line 12, column 1 of "current.sql":
|   alter table taxonomy_level
|     add constraint fk_taxonomy_level_parent foreign key (parent_id, project_id, environment_id)
|       references taxonomy_level (id, project_id, environment_id);
|   asdf;
| --^
| 42601: syntax error at or near "asdf"
    error: syntax error at or near "asdf"
        at Parser.parseErrorMessage (/Users/.../node_modules/pg-protocol/dist/parser.js:278:15)
        at Parser.handlePacket (/Users/.../node_modules/pg-protocol/dist/parser.js:126:29)
        at Parser.parse (/Users/.../node_modules/pg-protocol/dist/parser.js:39:38)
        at Socket.<anonymous> (/Users/.../node_modules/pg-protocol/dist/index.js:8:42)
        at Socket.emit (node:events:327:20)
        at addChunk (node:internal/streams/readable:304:12)
        at readableAddChunk (node:internal/streams/readable:279:9)
        at Socket.Readable.push (node:internal/streams/readable:218:10)
        at TCP.onStreamRead (node:internal/stream_base_commons:192:23)

    Severity:   ERROR
    Code:       42601

Breaking changes

I feel this can be implemented without much overhead.

Supporting development

I [tick all that apply]:

benjie commented 4 years ago

I'd be open to making this an option e.g. -S,--no-stack-trace, but not all errors are as beautiful as the one you have posted in this issue, sometimes they come from other sources and the stack trace is important in those cases.