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

Postgresql exceptions #353

Closed
jcristovao opened this issue Jan 16, 2015 · 11 comments
Closed

Postgresql exceptions #353

jcristovao opened this issue Jan 16, 2015 · 11 comments
Labels

Comments

@jcristovao
Copy link
Contributor

Hello,

Perhaps I'm missing something obvious, but I somewhat was expecting withStmt' to return a SqlError, not a user error:

user error (Postgresql.withStmt': bad result status FatalError (("PGRES_FATAL_ERROR","ERROR: duplicate key value violates...

I guess this as to do with using fail which then gets turned into a UserError/IOError by with.

Would there be any way to bracket an insert just on SqlError, or do I have to bracket into the far more general IOError?

Thanks

@snoyberg
Copy link
Member

I'm not able to work on the codebase right now (getting ready to travel), but this seems like a reasonable request. If someone sends a PR, I'll be happy to merge. Otherwise, I probably won't be able to get to this for another week or two.

@jcristovao
Copy link
Contributor Author

So, I've took a stab at this, let me know what you think.
Thanks!

@snoyberg
Copy link
Member

This looks good to me, sorry for the delayed review. Unless someone has an objection, I'd merge this in.

@jcristovao
Copy link
Contributor Author

Thanks!

@AKurilin
Copy link

Would this by any chance expose the underlying Postgres error code or whatever it is translated to by the library being used to execute the query? e.g. PostgreSQL.Simple exposes a type for constraint violation errors. It's useful to pattern-match against for insertions and updates, when you want to perform the operation first, and handle the exception, as opposed to the less reliable check & insert approach.

@jcristovao
Copy link
Contributor Author

That's precisely my use case, and why I submitted this patch ;)

@jonkri
Copy link

jonkri commented May 12, 2015

+1

@gregwebs
Copy link
Member

@snoyberg do you know what the status of this issue is?

@snoyberg
Copy link
Member

IIRC, I'm waiting for @jcristovao to send a PR with his change. Though if people are more eager to see this go out the door, anyone else could theoretically take @jcristovao's commit and send it as a PR him/herself.

@jcristovao
Copy link
Contributor Author

Ok, I forgot I did not actually submited this as a PR, my bad.
Will take care of this tomorrow

@jonkri
Copy link

jonkri commented May 12, 2015

Thanks! :)

jcristovao added a commit to jcristovao/persistent that referenced this issue May 28, 2015
snoyberg added a commit that referenced this issue May 28, 2015
Addresses  Postgresql exceptions #353
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants