graphile / migrate

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

Make error reporting work for multiple current migrations #127

Open ben-pr-p opened 3 years ago

ben-pr-p commented 3 years ago

Summary

When I have multiple files in my current migration, and I make an error, I get something like:

:octagonal_sign: Error occurred at line 67, column 1 of "current.sql":
|
|
|   )
| ^
| 42601: syntax error at or near ")"
    error: syntax error at or near ")"
        at Parser.parseErrorMessage (/Users/mgoldfield/Rewired/assemble/node_modules/pg-protocol/dist/parser.js:287:98)
        at Parser.handlePacket (/Users/mgoldfield/Rewired/assemble/node_modules/pg-protocol/dist/parser.js:126:29)
        at Parser.parse (/Users/mgoldfield/Rewired/assemble/node_modules/pg-protocol/dist/parser.js:39:38)
        at Socket.<anonymous> (/Users/mgoldfield/Rewired/assemble/node_modules/pg-protocol/dist/index.js:11:42)
        at Socket.emit (events.js:315:20)
        at addChunk (internal/streams/readable.js:309:12)
        at readableAddChunk (internal/streams/readable.js:284:9)
        at Socket.Readable.push (internal/streams/readable.js:223:10)
        at TCP.onStreamRead (internal/stream_base_commons.js:188:23)

    Severity:    ERROR
    Code:        42601

However, this was actually on line 21 of my third current migration file.

It'd be nice if

Steps to reproduce

Create multiple current migrations, and then make an error in one other than the first. The line numbers of the errors will not match up.

Expected results

Something like "Error occurred at line 21 of ".

Actual results

Error occurred at line 67, column 1 of "current.sql"

Additional context

Graphile-migrate 0.12.0

Possible Solution

I think we'll have to build a little source map in memory, storing file offsets?

Happy to take this one! Will approach it by storing file offsets unless you'd like a different approach.