[Proposal] Set domain, tags etc. via the context
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Non vengono indicati file di implementazione né test. Inizia leggendo le API esistenti di In, With, WithContext e del generatore di errori, quindi confronta le interfacce di contesto proposte e le loro interazioni. Il lavoro è completato quando un’interfaccia decisa è implementata, in modo che i campi trasportati dal contesto raggiungano gli errori più avanti nella catena di chiamate, con una copertura per l’esempio documentato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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)
- Lingua principale
- Go
- Stelle
- 996
- Fork
- 45
- Merge medio
- 1m
- PR unite (30g)
- 1
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di samber/oops
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
-
Feature Request: Allow adding context to an existing OopsError without regenerating stack traceAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
Can you add LastPublic(), LastCode() API?Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
Issue simili
-
[Bug]: Telegram bot (v3.11.0): "Ban log" no longer sends the current 3xipl-banned.logForse già presa @HamedSanaei l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
MHSanaei/3x-ui#6990 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
bug(tool/internal/instrument): identical inject_code rules from two rule packages are applied twiceAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
open-telemetry/opentelemetry-go-compile-instrumentation#1611 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
agent-butler-finding chore
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
jordansmall/spindrift#6114 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno