Exception: DuckDB::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/duckdb/error.rb,
ext/duckdb/error.c

Overview

The exception raised by ruby-duckdb.

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, error_type_id = nil) ⇒ Error

error_type_id is the raw DuckDB error type id, set by the C extension when a query result fails; it defaults to nil for all other errors.



8
9
10
11
# File 'lib/duckdb/error.rb', line 8

def initialize(message = nil, error_type_id = nil)
  super(message)
  @error_type_id = error_type_id
end

Instance Method Details

#error_typeObject

Returns the DuckDB error category as a Symbol (e.g. :constraint, :catalog, :parser), or nil when the error did not originate from a DuckDB query result (e.g. internal binding failures).

begin
con.query('INSERT INTO t VALUES (1)') # duplicate primary key
rescue DuckDB::Error => e
e.error_type # => :constraint
end


22
23
24
# File 'lib/duckdb/error.rb', line 22

def error_type
  @error_type_id && Converter::IntToSym.error_type_to_sym(@error_type_id)
end