Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[Proposal] Set domain, tags etc. via the context

オープン
#37 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
go
領域
backend

調査の方向性

実装ファイルやテストは指定されていません。まず既存の In、With、WithContext、およびエラービルダーの API を読み、その後、提案されているコンテキストインターフェースとそれらの相互作用を比較してください。完了の条件は、決定したインターフェースが実装され、コンテキストによって運ばれるフィールドが呼び出しチェーンのさらに下にあるエラーへ到達すること、およびドキュメント化された例をカバーすることです。

索引モデルが issue の本文から書いたものです。

説明

Having all fields for the error builder settable via context.Context would make it easy to make sure that any error further down in the chain has e.g., the domain set.

Motivation

For us the use case is that we have different areas of the code where it would be nice to always be able to ensure all errors have a domain or tags set.

Rather than enforcing everyone to remember to add In -- which sometimes might even be possible to figure out as you don't know what the call-chain is -- you set the In via the context and then as long as you do WithContext it will get set automatically.

Interface

In terms of interface I'm not sure what would be the best to avoid confusion. I can think of a few different ways

  1. Prefixing with With.
  2. Prefixing with WithContext.
  3. Prefixing with Context.
  4. Setting a default OopsErrorBuilder in the context.

(1) would have functions like WithIn. It has the advantage of being similar to other APIs when using context but doesn't play very nicely with the already existing function With (WithWith?).
(2) would have functions like WithContextIn. It is similar to the above but still sounds weird (WithContextWith?) and is maybe unnecessarily verbose without much clarity.
(3) would have functions like ContextIn or ContextTags which while not fully in line with what you would expect in therms of API doesn't collide with other names used and is also fairly clear what it would do.
(4) would need only two functions WithBuilder which sets a default builder in the context that can then be retrieved with FromContext(ctx).

Example

As an example of how it could look.

First of all, you add what you want to the context, using:

ctx := oops.WithBuilder(ctx, oops.In("domain"))

Then somewhere further down the call chain you then do

return oops.FromContext(ctx).Wrap(err)
主要言語
Go
スター
996
フォーク
45
平均マージ
1分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

samber/oops のほかの issue

samber/oops の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。