Skip to content
Myr

exit-code.ts

This file

Path

packages/protocol/src/exit-code.ts

88 lines · 2.6 KiB · TypeScript

Last changed by

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

History of this file

Take it

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

lines 1–2why, one step back
1// Codes from sysexits(3). Kept apart from `cli.ts` so the reference docs read
2// it without effect/cli. A tag's code is public: change one only with notice.

Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862

lines 3–41why, one step back
3import type { Array } from "effect";
45import type { Refusal } from "./refusal.ts";67export const ExitCode = {8 dataErr: 65,9 failed: 1,10 noInput: 66,11 noPerm: 77,12 ok: 0,13 tempFail: 75,14 unavailable: 69,15 usage: 2,16} as const;1718export type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];1920type FinalTag = Extract<Refusal, { readonly retryable: false }>["_tag"];2122type FinalCode =23 | typeof ExitCode.dataErr24 | typeof ExitCode.noInput25 | typeof ExitCode.noPerm;2627// Each final refusal's code. A new final tag fails the typecheck until it28// has one here; a retryable tag can't be given any but `tempFail`.29const final = {30 ChecksFailed: ExitCode.dataErr,31 DecisionClosed: ExitCode.noInput,32 Denounced: ExitCode.noPerm,33 DirectPush: ExitCode.noPerm,34 HeldBackFailed: ExitCode.dataErr,35 IncompleteBrief: ExitCode.dataErr,36 LayerContentInPublicTree: ExitCode.dataErr,37 NoAsk: ExitCode.noInput,38 NotDecider: ExitCode.noPerm,39 NotRedFirst: ExitCode.dataErr,40 NotSensitive: ExitCode.dataErr,41 NotVouched: ExitCode.noPerm,

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 42why, one step back
42 NotYourNamespace: ExitCode.noPerm,

Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862

lines 43–88why, one step back
43 OutOfScope: ExitCode.dataErr,
44 PostureChange: ExitCode.dataErr,45 PrivatePathInPublicTree: ExitCode.dataErr,46 ProjectExists: ExitCode.dataErr,47 ProposalClosed: ExitCode.noInput,48 ReachedInternals: ExitCode.dataErr,49 SecretInOutput: ExitCode.dataErr,50 TouchedJudge: ExitCode.dataErr,51 UnknownAsk: ExitCode.noInput,52 UnknownCommit: ExitCode.noInput,53 UnknownDecision: ExitCode.noInput,54 UnknownEnvItem: ExitCode.noInput,55 UnknownPath: ExitCode.noInput,56 UnknownProject: ExitCode.noInput,57 UnknownProposal: ExitCode.noInput,58 UnknownRevision: ExitCode.noInput,59 UnstatedRequirement: ExitCode.dataErr,60 ValueTooShort: ExitCode.dataErr,61 WeakCheck: ExitCode.dataErr,62 Weakened: ExitCode.dataErr,63} as const satisfies Record<FinalTag, FinalCode>;6465export const exitCodeOf = (refusal: Refusal): ExitCode =>66 refusal.retryable ? ExitCode.tempFail : final[refusal._tag];6768const finalCodes: ReadonlyMap<string, FinalCode> = new Map(69 Object.entries(final)70);7172export const exitCodeOfTag = (tag: string): ExitCode =>73 finalCodes.get(tag) ?? ExitCode.tempFail;7475export const precedence: readonly ExitCode[] = [76 ExitCode.noPerm,77 ExitCode.noInput,78 ExitCode.dataErr,79 ExitCode.tempFail,80];8182export const exitCodeFor = (83 refusals: Array.NonEmptyReadonlyArray<Refusal>84): ExitCode => {85 const codes = new Set(refusals.map(exitCodeOf));8687 return precedence.find((code) => codes.has(code)) ?? exitCodeOf(refusals[0]);88};