模块:OperationFailure::Family

扩展方式:
可转发
包括:
Mongo::Error::ReadWriteRetryableMongo::Error::SdamErrorDetection
包含在:
Mongo::Error::OperationFailureMongo::Error::ServerTimeoutError
定义于:
lib/ Mongo/error/operation_failure.rb

Overview

实现针对 OperationFailure 错误的行为。 其他错误(例如 ServerTimeoutError) 也可能会实现这一点,因此它们可能会被识别并视为 OperationFailure 错误。

常量摘要折叠

CHANGE_STREAM_RESUME_ERRORS =

此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。

错误代码和代码名称,应导致变更流上的 getMore 命令失败而无法恢复。

[
  { code_name: 'HostUnreachable', 代码: 6 },
  { code_name: ' HostNotFound ', 代码: 7 },
  { code_name: ' NetworkTimeout ', 代码: 89 },
  { code_name: ' ShutdownInProgress ', 代码: 91 },
  { code_name: ' PrimarySteppedDown ', 代码: 189 },
  { code_name: 'ExceededTimeLimit', 代码: 262 },
  { code_name: ' SocketException ', 代码: 9001 },
  { code_name: ' NotMaster ', 代码: 10 _ 107 },
  { code_name: ' InterruptedAtShutdown ', 代码: 11 _ 600 },
  { code_name: ' InterruptedDueToReplStateChange ', 代码: 11 _ 602 },
  { code_name: ' NotPrimaryNoSecondaryOk ', 代码: 13 _ 435 },
  { code_name: ' NotMasterOrSecondary ', 代码: 13 _ 436 },

  { code_name: ' StaleShardVersion ', 代码: 63 },
  { code_name: ' FailedToSatisfyReadPreference ', 代码: 133 },
  { code_name: 'StaleEpoch', 代码: 150 },
  { code_name: ' RetryChangeStream ', 代码: 234 },
  { code_name: ' StaleConfig ', 代码: 13 _ 388 },
].冻结
CHANGE_STREAM_RESUME_MESSAGES =

此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。

遇到这些错误消息时,可以恢复变更流。

由于:

  • 2.6.0

ReadWriteRetryable::WRITE_RETRY_MESSAGES

Mongo::Error::ReadWriteRetryable 中包含的常量

Mongo::Error::ReadWriteRetryable::RETRY_MESSAGESMongo::Error::ReadWriteRetryable::WRITE_RETRY_ERRORSMongo::Error::ReadWriteRetryable::WRITE_RETRY_MESSAGES

Mongo::Error::SdamErrorDetection 中包含的常量

Mongo::Error::SdamErrorDetection::NODE_RECOVERING_CodeS Mongo::Error::SdamErrorDetection::NODE_SHUTTING_down_codes Mongo::Error::SdamErrorDetection::NOT_MASTER_CodeS

实例属性摘要折叠

实例方法摘要折叠

Mongo::Error::ReadWriteRetryable 中包含的方法

#retryable? , #write_retryable?

Mongo::Error::SdamErrorDetection 中包含的方法

#node_recovering? , #node_shutting_down? , #not_master?

实例属性详细信息

# code整数(只读)

返回值 从文档中解析出的错误代码。

返回:

  • ( Integer )

    从文档中解析的错误代码。

由于:

  • 2.6.0



43
44
45
# File 'lib/ Mongo/error/operation_failure.rb', line 43

def 代码
  @code
end

# code_namestring (只读)

返回值 从文档中解析出的错误代码名称。

返回:

  • ( string )

    从文档中解析的错误代码名称。

由于:

  • 2.6.0



48
49
50
# File 'lib/ Mongo/error/operation_failure.rb', line 48

def code_name
  @code_name
end

#详细信息string | nil (只读)

返回 错误的详细信息。对于 WriteConcernErrors,此值为 document['writeConcernError']['errInfo']。对于 WriteErrors,此值为 document['writeErrors'][0]['errInfo']。对于所有其他错误,该值为零。

返回:

  • ( string | nil )

    错误的详细信息。对于 WriteConcernErrors,此值为 document['writeConcernError']['errInfo']。对于 WriteErrors,此值为 document['writeErrors'][0]['errInfo']。对于所有其他错误,该值为零。



151
152
153
# File 'lib/ Mongo/error/operation_failure.rb', line 151

def 详情
  @details
end

# 文档 =" BSON::Document | nil (只读)

返回值 服务器返回的错误文档。

返回:

  • ( BSON::Document | nil )

    服务器返回的错误文档。



156
157
158
# File 'lib/ Mongo/error/operation_failure.rb', line 156

def 文档
  @document
end

# 结果 操作::结果(只读)

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回操作的结果对象。

返回:



161
162
163
# File 'lib/ Mongo/error/operation_failure.rb', line 161

def 结果
  @result
end

# server_messagestring (只读)

返回值 从响应中解析出的服务器返回的错误消息。

返回:

  • ( string )

    从响应中解析出服务器返回的错误消息。



54
55
56
# File 'lib/ Mongo/error/operation_failure.rb', line 54

def server_message
  @server_message
end

# write_concern_error_code整数 | nil (只读)

如果存在写关注错误并具有代码,则返回该写关注错误的错误代码。

返回:

  • ( Integer | nil )

    写关注错误的错误代码(如果存在写关注错误并具有代码)。

由于:

  • 2.10.0



139
140
141
# File 'lib/ Mongo/error/operation_failure.rb', line 139

def write_concern_error_code
  @write_concern_error_code
end

# write_concern_error_code_namestring | nil (只读)

返回 如果写关注错误存在且具有代码名称,则为写关注错误的代码名称。

返回:

  • ( string | nil )

    如果写关注(write concern)错误存在且具有代码名称,则为写关注(write concern)关注错误的代码名称。

由于:

  • 2.10.0



145
146
147
# File 'lib/ Mongo/error/operation_failure.rb', line 145

def write_concern_error_code_name
  @write_concern_error_code_name
end

# write_concern_error_document哈希 | nil (只读)

返回服务器报告的写关注错误文档(如果有)。

返回:

  • ( Hash | nil )

    向服务器报告的写关注错误。



133
134
135
# File 'lib/ Mongo/error/operation_failure.rb', line 133

def write_concern_error_document
  @write_concern_error_document
end

实例方法详细信息

# change_stream_resumable?true , false

如果触发此错误的操作是 getMore,是否可以恢复发生此错误的变更流?

例子:

变更流的错误是否可恢复?

error.change_stream_resumable?

返回:

  • ( true , false )

    错误是否可恢复。

由于:

  • 2.6.0



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ Mongo/error/operation_failure.rb', line 96

def change_stream_resumable?
  if @result && @result.is_a?(mongo::操作::getMore::结果)
    # CursorNotFound 异常始终是可恢复的,因为服务器
    # 不知道游标 ID,因此无法确定是否
    # 游标是变更流,无法添加
    # ResumableChangeStreamError 标签。
    return true if 代码 == 43

    # 对于未确认的写入,不会填充连接描述。
    if connection_description.max_wire_version >= 9
      标签?('ResumableChangeStreamError')
    else
      change_stream_resumable_code?
    end
  else
    false
  end
end

# connection_descriptionServer::Description

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回执行此异常所指操作的服务器的MongoDB Server描述。

返回:

  • ( Server::Description )

    在该服务器上执行此异常所指操作的服务器描述。



38
# File 'lib/ Mongo/error/operation_failure.rb', line 38

def_delegator :@result, :connection_description

#initialize (message = nil, result = nil, options = {}) ⇒ 对象

创建操作失败。

参数:

  • message string (默认为: nil

    错误消息。

  • 结果 操作::结果 (默认为: nil

    结果对象。

  • 选项 哈希 (默认为: {}

    其他参数。

选项哈希 ( options ):

  • :code 整数

    错误代码。

  • :code_name string

    错误代码名称。

  • :文档 ( BSON::Document )

    服务器返回的错误文档。

  • server_message string

    从响应中解析出服务器返回的错误消息。

  • :write_concern_error_document 哈希

    服务器提供的写关注(write concern)错误文档(如果有)。

  • :write_concern_error_code 整数

    写关注(write concern)错误的错误代码(如有)。

  • :write_concern_error_code_name string

    写关注错误的错误代码名称(如有)。

  • :write_concern_error_labels ( Array<String> )

    写关注(write concern)错误的错误标签(如果有)。

  • :labels ( Array<String> )

    与错误相关的标签集。

  • :wtimeout ( true | false )

    错误是否为 wtimeout。



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/ Mongo/error/operation_failure.rb', line 186

def 初始化(message = nil, 结果 = nil, 选项 = {})
  @details = retrieve_details(选项[:文档])
  (append_details(message, @details))

  @result = 结果
  @code = 选项[:code]
  @code_name = 选项[:code_name]
  @write_concern_error_document = 选项[:write_concern_error_document]
  @write_concern_error_code = 选项[:write_concern_error_code]
  @write_concern_error_code_name = 选项[:write_concern_error_code_name]
  @write_concern_error_labels = 选项[:write_concern_error_labels] || []
  @labels = 选项[:labels] || []
  @wtimeout = !!选项[:wtimeout]
  @document = 选项[:文档]
  @server_message = 选项[:server_message]
end

# max_time_ms_expired?true | false

错误是否为 MaxTimeMSExpired。

返回:

  • ( true | false )

    错误是否为 MaxTimeMSExpired。

由于:

  • 2.10.0



217
218
219
# File 'lib/ Mongo/error/operation_failure.rb', line 217

def max_time_ms_expired?
  代码 == 50 # MaxTimeMSExpired
end

# write_concern_error?true | false

返回此故障是否包括写关注(write concern)错误。 故障可能具有顶级错误和写关注(write concern)错误,或两者之一。

返回:

  • ( true | false )

    故障是否包括写关注(write concern)错误。 故障可能具有顶级错误和写关注(write concern)错误,或两者之一。

由于:

  • 2.10.0



125
126
127
# File 'lib/ Mongo/error/operation_failure.rb', line 125

def write_concern_error?
  !!@write_concern_error_document
end

# wtimeout?true | false

错误是否为写关注(write concern)超时。

返回:

  • ( true | false )

    错误是否为写关注(write concern)超时。

由于:

  • 2.7.1



208
209
210
# File 'lib/ Mongo/error/operation_failure.rb', line 208

def wtimeout?
  @wtimeout
end