Skip to content

Commit

Permalink
Add driver level error classifiers and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ince committed Oct 11, 2018
1 parent b711895 commit 6c3ca48
Show file tree
Hide file tree
Showing 5 changed files with 453 additions and 32 deletions.
70 changes: 60 additions & 10 deletions neo4j/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ type driverError struct {
message string
}

type sessionExpiredError struct {
message string
}

func (failure *databaseError) BoltError() bool {
return true
}

func (failure *databaseError) Classification() string {
return failure.classification
}
Expand All @@ -56,6 +64,10 @@ func (failure *databaseError) Error() string {
return fmt.Sprintf("database returned error [%s]: %s", failure.code, failure.message)
}

func (failure *connectorError) BoltError() bool {
return true
}

func (failure *connectorError) State() int {
return failure.state
}
Expand All @@ -72,10 +84,26 @@ 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 (failure *driverError) BoltError() bool {
return true
}

func (failure *driverError) Message() string {
return failure.message
}

func (failure *driverError) Error() string {
return failure.message
}

func (failure *sessionExpiredError) BoltError() bool {
return true
}

func (failure *sessionExpiredError) Error() string {
return failure.message
}

func newDriverError(format string, args ...interface{}) gobolt.GenericError {
return &driverError{message: fmt.Sprintf(format, args...)}
}
Expand All @@ -92,20 +120,42 @@ func isRetriableError(err error) bool {
return gobolt.IsServiceUnavailable(err) || gobolt.IsTransientError(err) || gobolt.IsWriteError(err)
}

// IsServiceUnavailable is a utility method to check if the provided error can be classified
// to be in service unavailable category.
func IsServiceUnavailable(err error) bool {
return gobolt.IsServiceUnavailable(err)
// IsSecurityError is a utility method to check if the provided error is related with any
// TLS failure or authentication issues.
func IsSecurityError(err error) bool {
return gobolt.IsSecurityError(err)
}

// IsAuthenticationError is a utility method to check if the provided error is related with any
// authentication issues.
func IsAuthenticationError(err error) bool {
return gobolt.IsAuthenticationError(err)
}

// IsDriverError is a utility method to check if the provided error is generated by the driver
func IsDriverError(err error) bool {
_, ok := err.(*driverError)
return ok
// IsClientError is a utility method to check if the provided error is related with the client
// carrying out an invalid operation.
func IsClientError(err error) bool {
return gobolt.IsClientError(err)
}

// IsTransientError is a utility method to check if the provided error is a DatabaseError with
// TransientError classification
// IsTransientError is a utility method to check if the provided error is related with a temporary
// failure that may be worked around by retrying.
func IsTransientError(err error) bool {
return gobolt.IsTransientError(err)
}

// IsSessionExpired is a utility method to check if the session no longer satisfy the criteria
// under which it was acquired, e.g. a server no longer accepts write requests.
func IsSessionExpired(err error) bool {
if _, ok := err.(*sessionExpiredError); ok {
return true
}

return gobolt.IsSessionExpired(err)
}

// IsServiceUnavailable is a utility method to check if the provided error can be classified
// to be in service unavailable category.
func IsServiceUnavailable(err error) bool {
return gobolt.IsServiceUnavailable(err)
}
Loading

0 comments on commit 6c3ca48

Please sign in to comment.