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

[Bug] Network errors are discarded.

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

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
ruby
领域
api

调研方向

从 lib/graphql/client/http.rb 中 Either 风格返回值附近的代码,以及 lib/graphql/schema/loader.rb 中 load_schema 使用 dump_schema 的位置开始。跟踪错误路径经过 load_schema 和提到的其他 execute 调用方(包括 query()),然后确认 HTTP 或 GraphQL 错误仍然可用,而不会变成 KeyError。

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

描述

If there's an HTTP error, calls to GraphQL::Client can return this:

KeyError: key not found: "data" (KeyError)

E.g., when I try the example in the readme to https://example.com/graphql, I expect some kind of network or HTTP error. Instead, I get the above KeyError.

I got this when making changes to my infrastructure. It made it very hard to debug problems.


I looked at load_schema, and found:

pry(main)> GraphQL::Client.load_schema(HTTP)
KeyError: key not found: "data" (KeyError)
from gems/3.4.0/gems/graphql-2.5.2/lib/graphql/schema/loader.rb:17:in 'Hash#fetch'

The load_schema call turns into load_schema(dump_schema(HTTP)). dump_schema seems to return full error info. So, between those two function calls, the information is lost:

[pry(main)> GraphQL::Client.dump_schema(HTTP)
=> {"errors" => [{"message" => "403 Forbidden"}]}

This happens other places that call execute, I believe, like .query().


In my opinion, the core problem is, the library uses fp-style Either error returns. However, Ruby doesn't have a way (like Rust or Haskell do) to enforce the handling of the error case. And so, it's possible to simply not handle them appropriately, like here.

Either-style API:

https://github.com/github-community-projects/graphql-client/blob/aff58829ea27c7e59213756aab0bdfdb0e03941a/lib/graphql/client/http.rb#L62-L63

IMO, the fix is to use Ruby's Exception/Error facility so that library clients can meaningfully handle errors.

主要语言
Ruby
星标
78
派生
228
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

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

github-community-projects/graphql-client 的其他 Issue

查看 github-community-projects/graphql-client 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

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