GitLabgitlab-org

cli

main
ply6 git calls50 ms97 KiB4 cachedprotocol v2
97 lines2.4 KiBRaw
1package cmdutils
3import (
4 "context"
5 "errors"
6 "fmt"
7 "io"
9 "charm.land/fang/v2"
11 "gitlab.com/gitlab-org/cli/internal/iostreams"
14// FlagError is the kind of error raised in flag processing
15type FlagError struct {
16 Err error
19func (fe FlagError) Error() string {
20 return fe.Err.Error()
23func (fe FlagError) Unwrap() error {
24 return fe.Err
27var (
28 // SilentError is an error that triggers exit Code 1 without any error messaging
29 SilentError = errors.New("SilentError")
31 errCommandInterrupted = errors.New("the command execution has been interrupted")
34// NewGitLabErrorHandler returns a custom error handler for fang that handles
35// GitLab CLI specific errors. Under --output=json the failure is also written
36// to stdout as an object, so a caller parsing glab's output is not left with an
37// empty stream; the human-readable error still goes to stderr in every mode.
38//
39// fang passes only the error, never the *cobra.Command, so the format is read
40// back from streams. streams must not be nil.
41func NewGitLabErrorHandler(streams *iostreams.IOStreams) fang.ErrorHandler {
42 return func(w io.Writer, styles fang.Styles, err error) {
43 switch {
44 case errors.Is(err, context.Canceled):
45 err = errCommandInterrupted
46 case errors.Is(err, SilentError):
47 // Ignore SilentError - it should not produce any output
48 return
49 }
51 if streams.IsJSONOutput() {
52 if printErr := streams.PrintJSONError(err); printErr != nil {
53 err = errors.Join(err, printErr)
54 }
55 }
57 // Fang title-cases the first word of ErrorText, which rewrites
58 // case-sensitive tokens such as flags, config keys, and paths.
59 styles.ErrorText = styles.ErrorText.UnsetTransform()
61 // Delegate the human-readable rendering to Fang's default handler
62 fang.DefaultErrorHandler(w, styles, err)
63 }
66type ExitError struct {
67 Err error
68 Code int
69 Details string
72func WrapErrorWithCode(err error, code int, details string) *ExitError {
73 return &ExitError{
74 Err: err,
75 Code: code,
76 Details: details,
77 }
80func WrapError(err error, log string) *ExitError {
81 return WrapErrorWithCode(err, 1, log)
84func CancelError(log ...any) error {
85 if len(log) < 1 {
86 return WrapErrorWithCode(iostreams.ErrUserCancelled, 2, "action cancelled")
87 }
88 return WrapErrorWithCode(iostreams.ErrUserCancelled, 2, fmt.Sprint(log...))
91func (e *ExitError) Error() string {
92 return e.Err.Error()
95func (e ExitError) Unwrap() error {
96 return e.Err
Diagnostics6 git calls · 50 ms
CallStatusSizeTime050 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchtree:02001.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=43
git.response.bytes=1238
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=c10f4b8b760c3fec7ed8ca85e428d5bc523f8e17
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1238
git.pkt.payload.max=1211
git.sideband.band1.bytes=1211
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1211
git.pack.trailer=7373aa350f2a611db7d4116eb1450c92f18a27ca
Open pack map
fetch2001.1 KiB · hit43 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1141
git.response.cache=HIT
git.response.duration_ms=43
git.fetch.wants=efd1c01bd7ff58c23bc9d7b47b2aca140d25cd44
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1141
git.pkt.payload.max=1114
git.sideband.band1.bytes=1114
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e152499da50acb
Request
9ba3b232…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format