hyperstack-org / hyperstack-org/hyperstack

Hypermodel `after_commit` handler is dropping errors instead of raising

Đang mở
#453 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
538
Fork
41
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

in the after_commit method of hypermodel, the `SendPacket` operation is run which will return a promise, but it is not checked for an error state.

```ruby
def self.after_commit(operation, model)
# Calling public_columns_hash once insures all policies are loaded
# before the first broadcast.
@public_columns_hash ||= ActiveRecord::Base.public_columns_hash
Hyperstack::InternalPolicy.regulate_broadcast(model) do |data|
puts "Broadcast aftercommit hook: #{data}" if Hyperstack::Connection.show_diagnostics

if !Hyperstack.on_server? && Hyperstack::Connection.root_path
send_to_server(operation, data, model.__synchromesh_update_time) rescue nil # fails if server no longer running so ignore
else
SendPacket.run(data, operation: operation, updated_at: model.__synchromesh_update_time)
end
end
rescue ActiveRecord::StatementInvalid => e
raise e unless e.message == "Could not find table 'hyperstack_connections'"
end unless RUBY_ENGINE == 'opal'
```

The line containing `SendPacket` should be
```ruby
SendPacket.run(data, operation: operation, updated_at: model.__synchromesh_update_time).tap { |p| raise p.error if p.error }
```

The easiest way to patch this is by adding this:

```ruby
module Hyperstack
class InternalPolicy
alias original_send_message send_message
def send_message(*args, &block)
original_send_message(*args, &block).tap { |p| raise p.error if p.is_a?(Promise) && p.error }
end
end
end
```

This will catch the error with the smallest patch. Note the patch needs to check if its a promise, but the actual fix does not.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.