Exception: TreeHaver::BackendConflict

Inherits:
Error
  • Object
show all
Defined in:
lib/tree_haver.rb

Overview

Raised when attempting to use backends that are known to conflict

This is a serious error that extends Exception (not StandardError) because it prevents a segmentation fault. The MRI backend (ruby_tree_sitter) and FFI backend cannot coexist in the same process - once MRI loads, FFI will segfault when trying to set a language on a parser.

This protection can be disabled with ‘TreeHaver.backend_protect = false` but doing so risks segfaults.

Examples:

Handling backend conflicts

begin
  # This will raise if MRI was already used
  TreeHaver.with_backend(:ffi) { parser.language = lang }
rescue TreeHaver::BackendConflict => e
  puts "Backend conflict: #{e.message}"
  # Fall back to a compatible backend
end

Disabling protection (not recommended)

TreeHaver.backend_protect = false
# Now you can test backend conflicts (at risk of segfaults)