Skip to content

Add driver-side error codes to NpgsqlException #1072

Description

@roji

Since 3.1 we throw PostgresException for server-side errors and NpgsqlException for driver-side errors (e.g. network failure). It would be good to add an error code for driver-side errors to allow users to check for them programmatically, i.e. distinguish between SSL negotiation failure, network failure, missing PostgreSQL type when mapping...

Activity

  1. self-assigned this
    on May 8, 2016
  2. added this to the 3.2 milestone on May 8, 2016
  3. added a commit that references this issue on May 8, 2016
  4. modified the milestone: 3.2 on Sep 25, 2016
  5. roji commented on Jun 8, 2018

    @roji
    MemberAuthor

    Closing for age and lack of interest; NpgsqlException already wraps system exceptions which allow users to understand what happened. If there's interest in anything else, I'll accept a PR and we can also discuss.

  6. swjain23 commented on Jun 16, 2020

    @swjain23

    @roji - We were interested in adding the error code for SSL exception. Currently we are getting an NpgSQL exception with a message "SSL connection requested. No SSL enabled connection from this host is configured.".
    We want to identify this error and handle it separately. Having a proper error code will be very useful. We don't want to do a string match, are there any plans to address this?

  7. YohDeadfall commented on Jun 16, 2020

    @YohDeadfall
    Contributor

    We have no plans on this, but can accept a PR which will specify error codes for all our exceptions or for important at least.

  8. roji commented on Jun 16, 2020

    @roji
    MemberAuthor

    If we do something like this, we probably need to move SqlState up from PostgresException to NpgsqlException, and find a standard range within the SQL STATE standard where we can define our own error codes.

    Am going to open this for the backlog.

  9. reopened this on Jun 16, 2020
  10. added this to the Backlog milestone on Jun 16, 2020
  11. removed their assignment
    on Jun 16, 2020
  12. added theissue type on Jun 14, 2025
  13. linked a pull request that will close this issueAdd infrastructure for Npgsql error codes #4580on Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions