Class: Neo4j::Driver::Bolt::Message::Failure

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/driver/bolt/message/failure.rb

Overview

Failure response from Neo4j server.

Two wire shapes, both handled by #to_exception:

* Legacy (pre-Bolt 5.7): { code:, message: }.
* GQL (Bolt 5.7+): { gql_status:, description:, message:, neo4j_code:,
diagnostic_record:, cause: } — `cause` nests the same shape.

Since the driver speaks 5.7, a legacy failure is synthesised into the GQL shape (gql_status 50N42, default diagnostic record) so the exception exposes the same fields regardless of the server's protocol version — matching the Java driver's GqlStatusException behaviour.

Constant Summary collapse

EXCEPTION_FOR_CODE =

Code-prefix → driver exception class. Order matters: more specific patterns must come first.

[
  [%r{^Neo\.ClientError\.Security\.Unauthorized},         Exceptions::AuthenticationException],
  [%r{^Neo\.ClientError\.Security\.AuthorizationExpired}, Exceptions::AuthorizationExpiredException],
  [%r{^Neo\.ClientError\.Security\.TokenExpired},         Exceptions::TokenExpiredException],
  [%r{^Neo\.ClientError\.Security},                       Exceptions::SecurityException],
  [%r{^Neo\.ClientError\.Database\.DatabaseNotFound},     Exceptions::FatalDiscoveryException],
  [%r{^Neo\.ClientError},                                 Exceptions::ClientException],
  [%r{^Neo\.TransientError},                              Exceptions::TransientException],
  [%r{^Neo\.DatabaseError},                               Exceptions::DatabaseException]
].freeze
CODE_REWRITES =

Two TransientError codes the server may send that are actually non-retryable: the driver rewrites them to their ClientError form (so they map to a non-retryable ClientException, not a retryable TransientException) and surfaces the rewritten code. Mirrors the Java driver's ErrorUtil special-case; testkit's test_should_not_retry_non_retryable_tx_failures asserts both the rewritten code and that the managed-tx executor does not retry.

{
  'Neo.TransientError.Transaction.Terminated' => 'Neo.ClientError.Transaction.Terminated',
  'Neo.TransientError.Transaction.LockClientStopped' => 'Neo.ClientError.Transaction.LockClientStopped'
}.freeze
DEFAULT_DIAGNOSTIC_RECORD =

GQL diagnostic-record keys the server may omit; filled with these defaults so the record is always complete (mirrors the Java driver).

{ OPERATION: '', OPERATION_CODE: '0', CURRENT_SCHEMA: '/' }.freeze
DEFAULT_GQL_STATUS =

Fallback GQL status for a legacy (non-GQL) failure: 50N42 = "general processing exception - unexpected error".

'50N42'
DEFAULT_STATUS_DESCRIPTION_PREFIX =
'error: general processing exception - unexpected error. '
KNOWN_CLASSIFICATIONS =

Diagnostic-record classifications the spec recognises; anything else (or absent) surfaces as the catch-all UNKNOWN.

%w[CLIENT_ERROR DATABASE_ERROR TRANSIENT_ERROR].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata) ⇒ Failure

Returns a new instance of Failure.



58
59
60
# File 'lib/neo4j/driver/bolt/message/failure.rb', line 58

def initialize()
  @metadata = 
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



56
57
58
# File 'lib/neo4j/driver/bolt/message/failure.rb', line 56

def 
  @metadata
end

Instance Method Details

#accept(visitor) ⇒ Object



76
77
78
# File 'lib/neo4j/driver/bolt/message/failure.rb', line 76

def accept(visitor)
  visitor.on_failure(self)
end

#assert_success!Object



80
81
82
# File 'lib/neo4j/driver/bolt/message/failure.rb', line 80

def assert_success!
  raise to_exception
end

#codeObject



62
63
64
# File 'lib/neo4j/driver/bolt/message/failure.rb', line 62

def code
  @metadata[:neo4j_code] || @metadata[:code]
end

#messageObject



66
67
68
# File 'lib/neo4j/driver/bolt/message/failure.rb', line 66

def message
  @metadata[:message]
end

#terminal?Boolean

Returns:

  • (Boolean)


84
# File 'lib/neo4j/driver/bolt/message/failure.rb', line 84

def terminal? = true

#to_exceptionObject

Map this server FAILURE to its driver-side exception. Single owner of the code→exception logic — used to live in 4+ places.



72
73
74
# File 'lib/neo4j/driver/bolt/message/failure.rb', line 72

def to_exception
  gql?(@metadata) ? build_gql(@metadata) : build_legacy(@metadata)
end