Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Hypermodel `after_commit` handler is dropping errors instead of raising

未关闭
#453 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
rails, ruby
领域
backend

调研方向

从 Hypermodel 的 after_commit 方法开始,检查 SendPacket.run 的结果,然后阅读 InternalPolicy#send_message,以了解 promise 错误是如何处理的。完成的标准是:after-commit broadcast 中的错误会被抛出,而不是被丢弃,同时 server-not-running rescue 保持不变。

由索引模型根据 Issue 内容生成。

描述

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.

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

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:

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.

主要语言
JavaScript
星标
538
派生
41
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hyperstack-org/hyperstack 的其他 Issue

查看 hyperstack-org/hyperstack 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。