Skip to content

Commit

Permalink
wip: updating error handling behavior for the utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-monroe committed Aug 6, 2024
1 parent 85fb384 commit c2560fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
19 changes: 13 additions & 6 deletions lib/tapioca/gem/listeners/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ def compile_method(tree, symbol_name, constant, method, visibility = RBI::Public
return unless method_owned_by_constant?(method, constant)
return if @pipeline.symbol_in_payload?(symbol_name) && !@pipeline.method_in_gem?(method)

signature = signature_of(method, error_handler: ->(error) {
@pipeline.error_handler.call(<<~MSG)
Unable to compile signature for method: #{method.owner}##{method.name}
Exception raised when loading signature: #{error.inspect.squish}")
MSG
})
signature = lookup_signature_of(method)

method = T.let(signature.method, UnboundMethod) if signature

Expand Down Expand Up @@ -217,6 +212,18 @@ def initialize_method_for(constant)
def ignore?(event)
event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
end

sig { params(method: UnboundMethod).returns(T.untyped) }
def lookup_signature_of(method)
signature_of!(method)
rescue LoadError, StandardError => error
@pipeline.error_handler.call(<<~MSG)
Unable to compile signature for method: #{method.owner}##{method.name}
Exception raised when loading signature: #{error.inspect.squish}
MSG

nil
end
end
end
end
Expand Down
16 changes: 7 additions & 9 deletions lib/tapioca/runtime/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,15 @@ def qualified_name_of(constant)
end
end

sig do
params(
method: T.any(UnboundMethod, Method),
error_handler: T.nilable(T.proc.params(error: ::Exception).void)
).returns(T.untyped)
end
def signature_of(method, error_handler: nil)
sig { params(method: T.any(UnboundMethod, Method)).returns(T.untyped) }
def signature_of!(method)
T::Utils.signature_for_method(method)
rescue LoadError, StandardError => e
error_handler.call(e) if error_handler
end

sig { params(method: T.any(UnboundMethod, Method)).returns(T.untyped) }
def signature_of(method)
signature_of!(method)
rescue LoadError, StandardError
nil
end

Expand Down

0 comments on commit c2560fb

Please sign in to comment.