main
ply4 git calls33 ms42 KiB3 cachedprotocol v2
67 lines3.0 KiBRaw
1// HTTP status for every error code a response can carry: each of ply's codes, and the Worker's own (src/write/errors.ts).
2// `statusOfCode` is a switch over that closed union with no default: a code ply adds fails typecheck here until it is
3// mapped, and assertNever makes a code ply drops (a dead case) a type error too. test/status.test.ts checks the table.
4import { CODES } from 'ply'
5import { chainGet } from './absent.ts'
6import { assertNever } from './never.ts'
7import type { PlyCode } from './ply-result.ts'
8import { CODE_REF_EXISTS, CODE_STALE_EXPECTED, isWorkerCode, type WorkerCode } from './write/errors.ts'
10export type ErrorCode = PlyCode | WorkerCode
12export function statusOfCode(code: ErrorCode): number {
13 switch (code) {
14 case 'bad_request': return 400
15 case 'unsupported': return 501
16 case 'network': return 502
17 case 'timeout': return 504
18 case 'aborted': return 499
19 case 'http': return 502
20 case 'auth': return 401
21 case 'not_found': return 404
22 case 'rate_limited': return 429
23 case 'upstream_5xx': return 502
24 case 'not_git': return 502
25 case 'protocol': return 502
26 case 'pack_corrupt': return 502
27 case 'remote_error': return 502
28 case 'limit_exceeded': return 413
29 case 'match_count': return 422
30 case 'lfs_pointer': return 422
31 case 'cas_conflict': return 409
32 case 'push_rejected': return 409
33 case 'push_partial': return 409
34 case 'merge_conflict': return 409
35 case 'not_fast_forward': return 409
36 case 'not_linear': return 422
37 case 'unrelated_histories': return 422
38 case 'ambiguous': return 502
39 case 'internal': return 500
40 case CODE_REF_EXISTS: return 409
41 case CODE_STALE_EXPECTED: return 409
42 }
43 return assertNever(code)
46/** An own member of the code union. ply's isPlyCode is an `in` test, so an inherited name such as 'toString' passes it. */
47export function isErrorCode(code: unknown): code is ErrorCode {
48 return isWorkerCode(code) || CODES.some(known => known === code)
51const ALL_CODES: readonly ErrorCode[] = [...CODES, CODE_REF_EXISTS, CODE_STALE_EXPECTED]
53export const STATUS: Readonly<Record<string, number>> = Object.freeze(Object.fromEntries(ALL_CODES.map(code => [code, statusOfCode(code)])))
55/**
56 * `auth` keeps the upstream's own 401 or 403; anything unmapped is 500. An `http` error with a 3xx status is a redirect
57 * ply would not follow (git's http.followRedirects=initial: a 3xx on a POST, a loop past the hop cap, a Location that
58 * drops the info/refs suffix). The remote URL has to change, as with a cross-origin redirect the guard refuses: 400.
59 */
60export function statusOf(err: unknown): number {
61 const code = chainGet(err, 'code')
62 if (code.tag !== 'some' || !isErrorCode(code.value)) return 500
63 const status = chainGet(err, 'status')
64 if (code.value === 'auth' && status.tag === 'some' && (status.value === 401 || status.value === 403)) return status.value
65 if (code.value === 'http' && status.tag === 'some' && typeof status.value === 'number' && status.value >= 300 && status.value < 400) return 400
66 return statusOfCode(code.value)
Diagnostics4 git calls · 33 ms
CallStatusSizeTime033 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 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=41349
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921
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=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2001.3 KiB · hit28 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=28
git.response.bytes=1315
git.response.cache=HIT
git.response.duration_ms=28
git.fetch.wants=7e1fb27c0c2a46d42872f682985c94892f4a7437
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=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1315
git.pkt.payload.max=1294
git.sideband.band1.bytes=1293
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://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e2e5de6cb52947
Request
bb3fe451…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format