Skip to content

Error position #20

Open
Open
@alecmev

Description

@alecmev

I've hand-written a pretty large baseline migration, and then started debugging it by creating a fresh database and running postgres-migrations repeatedly. One problem I've run into is that crucial error details are lost inside this library, here:

} catch (err) {
try {
await cleanup()
} finally {
// eslint-disable-next-line no-unsafe-finally
throw new Error(
dedent`
An error occurred running '${migration.name}'. Rolled back this migration.
No further migrations were run.
Reason: ${err.message}`,
)
}
}

Sometimes PostgreSQL spews out messages like syntax error at or near ")", in a file full of functions, triggers, constraints, arrays, etc. The only way to find the cause for an error like that is to know the position, which is contained inside the err returned from the driver.

The easiest solution would probably be to extend the error message with Position: ${err.position}, but there may be some value is passing through the other fields too. An even better solution would be to print the problematic line and its surroundings, with the exact position pointed out with a ^, but that's a lot of extra effort for a small QoL improvement, so that's just an idea for the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions