This document describes error classes, codes, and recovery strategies for Ceradoc.
Error Class Hierarchy
Ceradoc::Error < StandardError (root base class)
│
├── Ceradoc::ParseError
│ └── Raised when document parsing fails
│
├── Ceradoc::ValidationError
│ └── Raised when document validation fails
│
├── Ceradoc::TransformationError
│ └── Raised when model transformation fails
│
├── Ceradoc::UnsupportedFormatError
│ └── Raised for unknown format requests
│
├── Ceradoc::ConfigurationError
│ └── Raised for configuration issues
│
├── Ceradoc::AsciiDoc::Error
│ ├── Ceradoc::AsciiDoc::ParseError
│ └── Ceradoc::AsciiDoc::Model::Serialization::Errors::AsciidocError
│ ├── ParseError
│ ├── MappingError
│ ├── ValidationError
│ └── SerializationError
│
├── Ceradoc::Html::Error
│ ├── UnknownTagError
│ └── InvalidConfigurationError
│
├── Ceradoc::Html::ConverterBase::ValidationError
├── Ceradoc::Html::ConverterBase::UnsupportedDocumentError
│
└── Ceradoc::Markdown::Error
├── ParseError
├── SerializationError
├── UnsupportedFeatureError
└── TransformationErrorBase Error Classes
Ceradoc::Error
The root error class for all Ceradoc errors.
begin
# Ceradoc operations
rescue Ceradoc::Error => e
puts "Ceradoc error: #{e.message}"
end message |
|
Ceradoc::ParseError
Raised when document parsing fails.
class Ceradoc::ParseError < Ceradoc::Error
attr_reader :line # Integer - Line number where error occurred
attr_reader :column # Integer - Column number where error occurred
attr_reader :source # String - Source text snippet
attr_reader :suggestion # String - Suggested fix (optional)
endbegin
doc = Ceradoc.parse(invalid_input, format: :asciidoc, strict: true)
rescue Ceradoc::ParseError => e
puts "Parse error at line #{e.line}, column #{e.column}"
puts "Source: #{e.source}"
puts "Suggestion: #{e.suggestion}" if e.suggestion
endCeradoc::ValidationError
Raised when document validation fails against a schema.
class Ceradoc::ValidationError < Ceradoc::Error
attr_reader :errors # Array<ValidationError> - List of errors
attr_reader :path # String - Path to invalid element
attr_reader :expected # String - Expected value/type
attr_reader :actual # Object - Actual value found
endbegin
result = schema.validate(document)
raise result.to_error unless result.valid?
rescue Ceradoc::ValidationError => e
e.errors.each do |err|
puts "#{err.path}: #{err.message}"
puts " Expected: #{err.expected}"
puts " Actual: #{err.actual}"
end
endCeradoc::UnsupportedFormatError
Raised when requesting an unsupported format.
class Ceradoc::UnsupportedFormatError < Ceradoc::Error
attr_reader :format # Symbol - The requested format
attr_reader :supported # Array<Symbol> - List of supported formats
endbegin
Ceradoc.convert(input, from: :asciidoc, to: :pdf)
rescue Ceradoc::UnsupportedFormatError => e
puts "Format '#{e.format}' is not supported"
puts "Supported formats: #{e.supported.join(', ')}"
endAsciiDoc Errors
Ceradoc::AsciiDoc::Error
Base error for AsciiDoc-specific errors.
begin
doc = Ceradoc::AsciiDoc.parse(input)
rescue Ceradoc::AsciiDoc::Error => e
puts "AsciiDoc error: #{e.message}"
endCeradoc::AsciiDoc::ParseError
Raised during AsciiDoc parsing.
-
Invalid block delimiters
-
Malformed tables
-
Unclosed inline formatting
-
Invalid attribute syntax
Parse error at line 42, column 15:
|=== invalid table
^
Expected: cell delimiter after format specification
Suggestion: Check table cell formattingHTML Errors
Ceradoc::Html::UnknownTagError
Raised when encountering unsupported HTML tags.
class Ceradoc::Html::UnknownTagError < Ceradoc::Html::Error
attr_reader :tag_name # String - The unknown tag
attr_reader :position # Integer - Position in document
endbegin
doc = Ceradoc.parse(html_input, format: :html)
rescue Ceradoc::Html::UnknownTagError => e
puts "Unknown tag: <#{e.tag_name}> at position #{e.position}"
endMarkdown Errors
Ceradoc::Markdown::ParseError
Raised during Markdown parsing.
-
Invalid link syntax
-
Unclosed code fences
-
Malformed tables
-
Invalid emphasis markers
Ceradoc::Markdown::UnsupportedFeatureError
Raised when using unsupported Markdown features.
class Ceradoc::Markdown::UnsupportedFeatureError < Ceradoc::Markdown::Error
attr_reader :feature # String - The unsupported feature
endbegin
doc = Ceradoc.parse(markdown_with_math, format: :markdown)
rescue Ceradoc::Markdown::UnsupportedFeatureError => e
puts "Feature '#{e.feature}' is not supported in Markdown"
endError Message Format
Error Recovery Strategies
Graceful Degradation
begin
doc = Ceradoc.parse(input, format: :asciidoc, strict: true)
rescue Ceradoc::ParseError => e
# Try parsing in non-strict mode
doc = Ceradoc.parse(input, format: :asciidoc, strict: false)
warn "Parsed with errors: #{e.message}"
endDebugging Tips
Enable Debug Mode
# Enable verbose error output
Ceradoc.debug = true
# Or via environment variable
ENV['CERADOC_DEBUG'] = 'true'Capture Full Error Context
begin
doc = Ceradoc.parse(input, format: :asciidoc)
rescue Ceradoc::ParseError => e
puts "Error: #{e.class}"
puts "Message: #{e.message}"
puts "Location: line #{e.line}, column #{e.column}"
puts "Source: #{e.source}" if e.respond_to?(:source)
puts "Backtrace:"
puts e.backtrace.first(5).join("\n")
endLog Errors for Analysis
require 'logger'
logger = Logger.new('ceradoc_errors.log')
begin
result = Ceradoc.parse(input, format: format)
rescue Ceradoc::Error => e
logger.error({
error_class: e.class.name,
message: e.message,
input_length: input.length,
format: format,
backtrace: e.backtrace
}.to_json)
raise
endCommon Error Scenarios
Table Parsing Errors
| Error | Cause | Solution | |-------|-------|----------| | Unclosed table | Missing \|=== | Add closing delimiter | | Invalid cell format | Wrong format spec | Check colspan/rowspan syntax | | Missing delimiter | No cell separator | Add \| between cells |
Exit Codes (CLI)
| Code | Meaning | Recovery | |------|---------|----------| | 0 | Success | - | | 1 | General error | Check error message | | 2 | Parse error | Fix input syntax | | 3 | Validation error | Fix validation issues | | 4 | Unsupported format | Use supported format | | 5 | File not found | Check file path | | 6 | Configuration error | Check config file | | 7 | Permission denied | Check file permissions |
Reporting Errors
When reporting errors, include:
-
Error class and message - From the exception
-
Input that caused the error - Minimal reproducible example
-
Expected behavior - What should have happened
-
Environment - Ruby version, Ceradoc version
# Generate error report
def error_report(error, input)
<<~REPORT
Error Class: #{error.class}
Message: #{error.message}
Location: line #{error.line}, column #{error.column}
Ruby: #{RUBY_VERSION}
Ceradoc: #{Ceradoc::VERSION}
Input (first 500 chars):
#{input[0, 500]}
REPORT
end