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

Exception Messages End with Newline #584

Closed
archuserr opened this issue Sep 5, 2017 · 2 comments
Closed

Exception Messages End with Newline #584

archuserr opened this issue Sep 5, 2017 · 2 comments
Milestone

Comments

@archuserr
Copy link

archuserr commented Sep 5, 2017

It looks like all the exception messages end with a newline char. That's inconsistent with both the Python standard library and all the third-party libraries I've worked with.

I searched the psycopg python files and didn't find the error messages, so I assume those (and the newline) come from the Postgres library.

I solved the problem by adding [:-1] to the exception messages. Would it make sense to make that change in psycopg?

@dvarrazzo
Copy link
Member

It may make sense or not. The messages are multiline: if they were a single line I would agree with you, but being multiline it's a bit like a file: some conventions assume a final newline, some don't.

try:
    cur.execute("select noway")
except Exception as e:
    pass

str(e)
'column "noway" does not exist\nLINE 1: select noway\n               ^\n'

Maybe if I started the library from scratch I would strip these, and maybe I wouldn't even use the entire message but only the primary.

e.diag.message_primary
'column "noway" does not exist'

However now there is code used to the trailing whiteline written since the last century: I don't feel like changing this in a backward-compatible library. So I guess it's a thing for a mythical psycopg3.

One remark: your solution is brittle: if we "fixed" psycopg you would start chopping the last character of the message - and this is the exact reason why I don't want to change this behaviour out of the blue. I advise you to use .rstrip() instead.

@dvarrazzo dvarrazzo added this to the psycopg3 milestone Sep 5, 2017
@dvarrazzo
Copy link
Member

Psycopg3 uses the message_primary.

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