Module: LogStruct::Integrations::Sorbet
- Extended by:
- IntegrationInterface, T::Sig
- Defined in:
- lib/log_struct/integrations/sorbet.rb
Overview
Integration for Sorbet runtime type checking error handlers This module installs error handlers that report type errors through LogStruct These handlers can be enabled/disabled using configuration
Class Method Summary collapse
-
.add_backtrace(error) ⇒ void
Starts the error's backtrace at the code that failed, below sorbet-runtime's frames (and this file's).
-
.setup(config) ⇒ Boolean?
Set up Sorbet error handlers to report errors through LogStruct.
Methods included from IntegrationInterface
Class Method Details
.add_backtrace(error) ⇒ void
This method returns an undefined value.
Starts the error's backtrace at the code that failed, below sorbet-runtime's frames (and this file's). sorbet-runtime passes some errors without raising them, which have no backtrace at all.
55 56 57 58 |
# File 'lib/log_struct/integrations/sorbet.rb', line 55 def self.add_backtrace(error) frames = error.backtrace || caller error.set_backtrace(frames.drop_while { |frame| frame.include?(__FILE__) || frame.include?("sorbet-runtime") }) end |
.setup(config) ⇒ Boolean?
Set up Sorbet error handlers to report errors through LogStruct
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/log_struct/integrations/sorbet.rb', line 17 def self.setup(config) return nil unless config.integrations.enable_sorbet_error_handlers # Install inline type error handler # Called when T.let, T.cast, T.must, etc. fail T::Configuration.inline_type_error_handler = lambda do |error, _opts| add_backtrace(error) LogStruct.handle_exception(error, source: LogStruct::Source::TypeChecking) end # Install call validation error handler # Called when method signature validation fails T::Configuration.call_validation_error_handler = lambda do |_signature, opts| error = TypeError.new(opts[:pretty_message]) add_backtrace(error) LogStruct.handle_exception(error, source: LogStruct::Source::TypeChecking) end # Install sig builder error handler # Called when there's a problem with a signature definition T::Configuration.sig_builder_error_handler = lambda do |error, _location| add_backtrace(error) LogStruct.handle_exception(error, source: LogStruct::Source::TypeChecking) end # Install sig validation error handler # Called when there's a problem with a signature validation T::Configuration.sig_validation_error_handler = lambda do |error, _opts| add_backtrace(error) LogStruct.handle_exception(error, source: LogStruct::Source::TypeChecking) end true end |