Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[First Draft] postgre: add more error information to an error message (position, line number, partial SQL) #203

Conversation

silbinarywolf
Copy link
Contributor

@silbinarywolf silbinarywolf commented Mar 6, 2021

Hey there!

This is a proof-of-concept PR to see if we can improve error reporting as per issue: #102

I understand that this isn't the nicest code approach as of yet and that we may want to maybe move this into the dbutil package or similar and also look at having tests for error behaviour.

Sample migration file:

-- migrate:up
CREATE TABLE test (
    test_id uuid NOT NULL
);
COMMENT ON TABLE test IS 'Here is my test table';

CREATE TABLE test_mistake (
    -- uh oh, comma here on the last field, error!
    test_mistake_id uuid NOT NULL,
);

-- migrate:down
DROP TABLE test;
DROP TABLE test_mistake;

Error messages previously:

pq: syntax error at or near "CREATE"

Errors messages after PR:

Error: position: 229, line: 9, column: 35, sql: field, error!
    test_mistake_id uuid NOT NULL,
);

: pq: syntax error at or near ")"

@amacneil
Copy link
Owner

amacneil commented Mar 9, 2021

This is an incredibly cool approach - I hadn't thought of inspecting the pq.Error for this information.

I'm definitely happy to merge this PR if you can extract the error parsing logic into a separate function (or delegate it to the driver - I assume only postgres will be supported for now), add test cases, etc.

In terms of the output, it would be nice to do something similar to whatever psql reports, but we can also improve on that if it is sensitible.

@silbinarywolf silbinarywolf changed the title postgre: add more error information to an error message (position, line number, partial SQL) [First Draft] postgre: add more error information to an error message (position, line number, partial SQL) Mar 13, 2021
@silbinarywolf
Copy link
Contributor Author

Going to close this off in favour of PR:
#204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants