[Proposal] Set domain, tags etc. via the context
まだ誰も着手していません。
評価
調査の方向性
実装ファイルやテストは指定されていません。まず既存の 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
- Prefixing with
With. - Prefixing with
WithContext. - Prefixing with
Context. - Setting a default
OopsErrorBuilderin 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
samber/oops のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
-
Feature Request: Allow adding context to an existing OopsError without regenerating stack traceオープン
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
Can you add LastPublic(), LastCode() API?対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
似ている issue
-
VLAgent `spec.k8sCollector.includePodLabels: false` has no effect対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
VictoriaMetrics/operator#2772 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Gaurav-Gosain/tuios#1316 ·
メンテナーはふだん 1 日以内に返信
-
needs: investigation
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
area:auth documentation priority:low
難易度 1/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
Mend: dependency security vulnerability
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
kube-tarian/sigrun#203 ·