This document describes error classes, codes, and recovery strategies for Ceradoc.

Error Class Hierarchy

Ceradoc Error 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
    └── TransformationError

Base 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
Attributes
message

String - Error 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)
end
Example
begin
  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
end

Ceradoc::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
end
Example
begin
  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
end

Ceradoc::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
end
Example
begin
  Ceradoc.convert(input, from: :asciidoc, to: :pdf)
rescue Ceradoc::UnsupportedFormatError => e
  puts "Format '#{e.format}' is not supported"
  puts "Supported formats: #{e.supported.join(', ')}"
end

AsciiDoc 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}"
end

Ceradoc::AsciiDoc::ParseError

Raised during AsciiDoc parsing.

Common Causes
  • Invalid block delimiters

  • Malformed tables

  • Unclosed inline formatting

  • Invalid attribute syntax

Example Error Message
Parse error at line 42, column 15:
  |=== invalid table
              ^
Expected: cell delimiter after format specification
Suggestion: Check table cell formatting

HTML Errors

Ceradoc::Html::Error

Base error for HTML-related 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
end
Example
begin
  doc = Ceradoc.parse(html_input, format: :html)
rescue Ceradoc::Html::UnknownTagError => e
  puts "Unknown tag: <#{e.tag_name}> at position #{e.position}"
end

Ceradoc::Html::InvalidConfigurationError

Raised for invalid HTML converter configuration.

begin
  Ceradoc::Html.serialize(doc, theme: :nonexistent)
rescue Ceradoc::Html::InvalidConfigurationError => e
  puts "Invalid configuration: #{e.message}"
end

Markdown Errors

Ceradoc::Markdown::Error

Base error for Markdown-specific errors.

Ceradoc::Markdown::ParseError

Raised during Markdown parsing.

Common Causes
  • 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
end
Example
begin
  doc = Ceradoc.parse(markdown_with_math, format: :markdown)
rescue Ceradoc::Markdown::UnsupportedFeatureError => e
  puts "Feature '#{e.feature}' is not supported in Markdown"
end

Error Message Format

Standard Format

All error messages follow this format:

[ERROR_TYPE] Error at line X, column Y:
  Source line content here
       ^-- Indicator
Message: Description of the error
Suggestion: How to fix it (if available)

Example Parse Error

[PARSE_ERROR] Error at line 15, column 8:
  | Cell 1 | Cell 2 | Cell 3
          ^
Expected: cell delimiter '|'
Message: Unexpected content in table cell
Suggestion: Ensure cells are separated by '|'

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}"
end

Validation with Fallback

result = schema.validate(document)
unless result.valid?
  # Log errors but continue
  result.errors.each { |e| logger.warn("Validation: #{e.message}") }

  # Use document anyway if errors are not critical
  document = result.document if result.errors.none?(&:critical?)
end

Format Detection

def safe_convert(input, to:)
  # Try to detect format
  format = detect_format(input)

  begin
    Ceradoc.convert(input, from: format, to: to)
  rescue Ceradoc::UnsupportedFormatError => e
    # Fall back to AsciiDoc
    Ceradoc.convert(input, from: :asciidoc, to: to)
  end
end

Debugging 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")
end

Log 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
end

Common 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 |

List Parsing Errors

| Error | Cause | Solution | |-------|-------|----------| | Invalid nesting | Wrong indentation | Check list level markers | | Unclosed continuation | Missing content | Add content after + | | Mixed markers | Inconsistent markers | Use consistent list markers |

Inline Formatting Errors

| Error | Cause | Solution | |-------|-------|----------| | Unclosed emphasis | Missing closing marker | Add closing _ or * | | Invalid link | Missing URL | Add URL in [] or () | | Nested formatting | Conflicting markers | Check nesting rules |

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:

  1. Error class and message - From the exception

  2. Input that caused the error - Minimal reproducible example

  3. Expected behavior - What should have happened

  4. 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

This site uses Just the Docs, a documentation theme for Jekyll.