Module: SimpleCov::Formatter::AIFormatter::MarkdownBuilder::DecodeGuard

Extended by:
T::Sig
Defined in:
lib/simplecov-ai/markdown_builder/decode_guard.rb

Overview

Contains the errors SimpleCov raises while it materialises a file's coverage data from a corrupt resultset, so one undecodable file degrades to an error entry and the rest of the report is still produced (SCAI-REQ-011). SimpleCov < 1.0 decodes the stringified branch descriptors of a merged result with eval, so a malformed descriptor raises SyntaxError — a ScriptError, which a StandardError rescue lets through and which would otherwise abort the whole at_exit report; SimpleCov >= 1.0's RubyDataParser raises ArgumentError instead, and malformed hit counts or line arrays fail with whatever NoMethodError or TypeError they provoke. SyntaxError is the only ScriptError contained: a NotImplementedError or LoadError is a defect, not undecodable data, and propagates.

Constant Summary collapse

ERROR_TEMPLATE =

Entry standing in for the deficits or bypasses of a file whose coverage data could not be decoded; the placeholder names the error class SimpleCov raised.

T.let(
  "  - **ERROR:** SimpleCov could not decode this file's coverage data (%s); skipped.\n", String
)

Class Method Summary collapse

Class Method Details

.attempt(fallback, &blk) ⇒ Object



37
38
39
40
41
# File 'lib/simplecov-ai/markdown_builder/decode_guard.rb', line 37

def self.attempt(fallback, &blk)
  yield
rescue StandardError, SyntaxError
  fallback
end

.render(&blk) ⇒ Object



49
50
51
52
53
# File 'lib/simplecov-ai/markdown_builder/decode_guard.rb', line 49

def self.render(&blk)
  yield
rescue StandardError, SyntaxError => error
  [format(ERROR_TEMPLATE, error.class)]
end