Exception: SearchSolrTools::Errors::HarvestError
- Inherits:
-
StandardError
- Object
- StandardError
- SearchSolrTools::Errors::HarvestError
- Includes:
- SSTLogger
- Defined in:
- lib/search_solr_tools/errors/harvest_error.rb
Constant Summary collapse
- ERRCODE_SOLR_PING =
1
- ERRCODE_SOURCE_PING =
2
- ERRCODE_SOURCE_NO_RESULTS =
4
- ERRCODE_SOURCE_HARVEST_ERROR =
8
- ERRCODE_DOCUMENT_INVALID =
16
- ERRCODE_INGEST_ERROR =
32
- ERRCODE_OTHER =
128
- ERRCODE_DESC =
{ ERRCODE_SOLR_PING => 'Solr instance did not return a successful ping', ERRCODE_SOURCE_PING => 'Source to be harvested did not return a successful ping', ERRCODE_SOURCE_NO_RESULTS => 'Source to be harvested returned no documents matching query', ERRCODE_SOURCE_HARVEST_ERROR => 'One or more source documents returned an error when trying to retrieve or translate', ERRCODE_DOCUMENT_INVALID => 'One or more documents to be harvested was invalid (malformed)', ERRCODE_INGEST_ERROR => 'Solr returned an error trying to ingest one or more harvested documents', ERRCODE_OTHER => 'General error code for non-harvest related issues' }.freeze
- PING_ERRCODE_MAP =
{ 'ping_solr' => ERRCODE_SOLR_PING, 'ping_source' => ERRCODE_SOURCE_PING }.freeze
- STATUS_ERRCODE_MAP =
{ Helpers::HarvestStatus::HARVEST_NO_DOCS => ERRCODE_SOURCE_NO_RESULTS, Helpers::HarvestStatus::HARVEST_FAILURE => ERRCODE_SOURCE_HARVEST_ERROR, Helpers::HarvestStatus::INGEST_ERR_INVALID_DOC => ERRCODE_DOCUMENT_INVALID, Helpers::HarvestStatus::INGEST_ERR_SOLR_ERROR => ERRCODE_INGEST_ERROR, Helpers::HarvestStatus::OTHER_ERROR => ERRCODE_OTHER }.freeze
Constants included from SSTLogger
Class Method Summary collapse
-
.code_to_list(code) ⇒ Object
Loop through all bit-flag values to produce a list of integers.
-
.describe_exit_code(code = -1)) ⇒ Object
If code is -1, it means display all error codes.
Instance Method Summary collapse
-
#exit_code ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(status, message = nil) ⇒ HarvestError
constructor
A new instance of HarvestError.
-
#message ⇒ Object
rubocop:enable Metrics/AbcSize.
Methods included from SSTLogger
Constructor Details
#initialize(status, message = nil) ⇒ HarvestError
Returns a new instance of HarvestError.
70 71 72 73 74 75 |
# File 'lib/search_solr_tools/errors/harvest_error.rb', line 70 def initialize(status, = nil) @status_data = status = super end |
Class Method Details
.code_to_list(code) ⇒ Object
Loop through all bit-flag values to produce a list of integers
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/search_solr_tools/errors/harvest_error.rb', line 56 def self.code_to_list(code) code = code.to_i code_list = [] [128, 64, 32, 16, 8, 4, 2, 1].each do |k| if code >= k || code == -1 code_list.prepend k code -= k unless code == -1 end end code_list end |
.describe_exit_code(code = -1)) ⇒ Object
If code is -1, it means display all error codes
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/search_solr_tools/errors/harvest_error.rb', line 42 def self.describe_exit_code(code = -1) code_list = code_to_list(code) codes = {} code_list.each do |k| next if code == -1 && !ERRCODE_DESC.keys.include?(k) # skip INVALID CODE if showing all codes codes[k] = ERRCODE_DESC.keys.include?(k) ? ERRCODE_DESC[k] : 'INVALID CODE NUMBER' end codes end |
Instance Method Details
#exit_code ⇒ Object
rubocop:disable Metrics/AbcSize
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/search_solr_tools/errors/harvest_error.rb', line 78 def exit_code if @status_data.nil? logger.error "OTHER ERROR REPORTED: #{@other_message}" return ERRCODE_OTHER end logger.error "EXIT CODE STATUS:\n#{@status_data.status}" code = 0 code += ERRCODE_SOLR_PING unless @status_data.ping_solr code += ERRCODE_SOURCE_PING unless @status_data.ping_source code += ERRCODE_SOURCE_NO_RESULTS if @status_data.status[Helpers::HarvestStatus::HARVEST_NO_DOCS].positive? code += ERRCODE_SOURCE_HARVEST_ERROR if @status_data.status[Helpers::HarvestStatus::HARVEST_FAILURE].positive? code += ERRCODE_DOCUMENT_INVALID if @status_data.status[Helpers::HarvestStatus::INGEST_ERR_INVALID_DOC].positive? code += ERRCODE_INGEST_ERROR if @status_data.status[Helpers::HarvestStatus::INGEST_ERR_SOLR_ERROR].positive? code = ERRCODE_OTHER if code.zero? code end |
#message ⇒ Object
rubocop:enable Metrics/AbcSize
100 101 102 |
# File 'lib/search_solr_tools/errors/harvest_error.rb', line 100 def self.class.describe_exit_code(exit_code).map { |_c, v| v }.join("\n") end |