Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.
/ gobolt Public archive

Commit

Permalink
Update error classification
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ince committed Aug 23, 2018
1 parent 17a8452 commit 0b6b668
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
6 changes: 0 additions & 6 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ func (connection *neo4jConnection) DiscardAll() (RequestHandle, error) {

func (connection *neo4jConnection) assertReadyState() error {
if connection.cInstance.status != C.BOLT_READY {
if connection.cInstance.error == C.BOLT_SERVER_FAILURE {
status := connection.valueSystem.valueAsDictionary(C.BoltConnection_failure(connection.cInstance))

return NewDatabaseError(status)
}

return newConnectionError(connection, "connection is not in READY state")
}

Expand Down
54 changes: 40 additions & 14 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ func (failure *ConnectorError) Error() string {
return fmt.Sprintf("expected connection to be in READY state, where it is %d [error is %d]", failure.state, failure.code)
}

func newConnectionError(connection *neo4jConnection, description string) error {
if connection.cInstance.error == C.BOLT_SERVER_FAILURE {
status := connection.valueSystem.valueAsDictionary(C.BoltConnection_failure(connection.cInstance))

return NewDatabaseError(status)
}

return newConnectionErrorWithCode(connection.cInstance.status, connection.cInstance.error, description)
}

func NewDatabaseError(details map[string]interface{}) error {
var ok bool
var codeInt, messageInt interface{}
Expand All @@ -102,10 +112,6 @@ func NewDatabaseError(details map[string]interface{}) error {
return &DatabaseError{code: code, message: message, classification: classification}
}

func newConnectionError(connection *neo4jConnection, description string) error {
return newConnectionErrorWithCode(connection.cInstance.status, connection.cInstance.error, description)
}

func newConnectionErrorWithCode(state uint32, code uint32, description string) error {
return &ConnectorError{state: state, code: code, description: description}
}
Expand Down Expand Up @@ -140,28 +146,48 @@ func IsTransientError(err error) bool {
return false
}

func IsWriteError(err error) bool {
if dbErr, ok := err.(*DatabaseError); ok {
switch dbErr.code {
case "Neo.ClientError.Cluster.NotALeader":
fallthrough
case "Neo.ClientError.General.ForbiddenOnReadOnlyDatabase":
return true
}
}

return false
}

// IsServiceUnavailable checkes whether given err represents a service unavailable status
func IsServiceUnavailable(err error) bool {
if IsDatabaseError(err) {
// TODO: Add specific failure codes while adding routing driver support
return false
} else if IsConnectorError(err) {
if IsConnectorError(err) {
switch err.(*ConnectorError).code {
case C.BOLT_END_OF_TRANSMISSION:
case C.BOLT_INTERRUPTED:
fallthrough
case C.BOLT_TLS_ERROR:
case C.BOLT_CONNECTION_RESET:
fallthrough
case C.BOLT_NETWORK_UNREACHABLE:
case C.BOLT_NO_VALID_ADDRESS:
fallthrough
case C.BOLT_TIMED_OUT:
fallthrough
case C.BOLT_CONNECTION_REFUSED:
fallthrough
case C.BOLT_INTERRUPTED:
case C.BOLT_NETWORK_UNREACHABLE:
fallthrough
case C.BOLT_CONNECTION_RESET:
case C.BOLT_TLS_ERROR:
fallthrough
case C.BOLT_END_OF_TRANSMISSION:
fallthrough
case C.BOLT_POOL_FULL:
fallthrough
case C.BOLT_TIMED_OUT:
case C.BOLT_ADDRESS_NOT_RESOLVED:
fallthrough
case C.BOLT_ROUTING_UNABLE_TO_RETRIEVE_ROUTING_TABLE:
fallthrough
case C.BOLT_ROUTING_UNABLE_TO_REFRESH_ROUTING_TABLE:
fallthrough
case C.BOLT_ROUTING_NO_SERVERS_TO_SELECT:
return true
}
}
Expand Down

0 comments on commit 0b6b668

Please sign in to comment.