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

Add "Detail" to PgError.Error() #87

Open
DmitriyVTitov opened this issue Aug 26, 2021 · 2 comments
Open

Add "Detail" to PgError.Error() #87

DmitriyVTitov opened this issue Aug 26, 2021 · 2 comments

Comments

@DmitriyVTitov
Copy link

I think current error message lacks some important information.
For example, when I try to insert a record and operation violates some constraint, then error message (PgError.Message) does not contain info about which record caused the error. It only says than constraint violation occured.
Could you please add Detail filed to (pe *PgError) Error() method?
I know that I can cast err to pgconn.PgError, but I think it would be more conveniently to see error details by default.

@jackc
Copy link
Owner

jackc commented Aug 28, 2021

That would be convenient in many cases. But I'm concerned about how long the error message could be. DETAIL sometimes echos back the entire failing row. This could make the error message hundreds of characters long. I don't think there is an actual hard rule about how long a Go error string should be, but it seems idiomatic to be pretty short. There's also the matter of how to format it. psql splits that type of error onto multiple lines. e.g.

ERROR:  23502: null value in column "user_name" of relation "users" violates not-null constraint
DETAIL:  Failing row contains (1, null, , , null, f, 2021-08-28 09:30:06.519231-05, 2021-08-28 09:30:06.519231-05, fejklf aefwe wekjfajwe ekfjljawe awfekljfkwelaj efkjfwelewkj ewk..., null, null, t, t, f, f, f, f, f, f, f, f, f, null, null, t, f, f, f).

I'm willing to concede if there is a strong consensus for this, but otherwise I think it should stay just the message.

@DmitriyVTitov
Copy link
Author

DmitriyVTitov commented Aug 28, 2021

Maybe you should return say first 100 bytes of Detail message?
I got your point but in my experience error messages themselves are pretty useless: something like SQL ERROR 23305. So choose yourself but I think some additional info required.

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

No branches or pull requests

2 participants