Skip to content

fix(cli)!: exit with the heibench codes for usage and environment - #69

Merged
CameronBrooks11 merged 1 commit into
mainfrom
fix/exit-codes
Nov 20, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
fix/exit-codes

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

Applies the ruling on #66: wikisync exits on the heibench table. This breaks scripts, so it ships as 0.7.0 in a release PR after this one.

Case Before After
unknown command or flag, nothing to pull, first pull without --host, bad --depth, a different wiki, push --apply without --summary 2 64
pull --watchlist / push --apply without credentials 2 4
login failed 1 4
wiki unreachable, HTTP error, server error during pull 1 4
working tree or local file can't be read or written (status, diff, push, pull) 1 4
push: the wiki declines an edit (protectedpage, editconflict, abuse filter, edit result not Success) 1, error line 1, new refused line
push: the wiki or the connection fails on a page (server error, readonly, maxlag, ratelimited, lost session, transport, HTTP status) 1 4, error line
push with both in one run 1 4
conflict, skipped page, untracked title, pull wrote nothing, --max exceeded 1 1
edit landed, saved text unreadable 0 + warning 0 + warning

mw.Refused classifies the error. It lives beside the client because it reads MediaWiki's error codes. apiError is exported as APIError so the core tests can build one, and an edit result other than Success wraps the new mw.ErrEditFailed; its message is unchanged. core.Push marks a declined request PushRefused.

The core test fake answered a stale baserevid with a plain error. It now answers with the editconflict API error the real wiki sends, so that test expects refused. The integration test's success check also rules out refused.

Tests: the expected codes in TestRun, TestLoginNeedsCredentials and TestPullWatchlistLogsInFirst move to the new values. New tests:

  • mw: Refused over 8 responses through the real request path
  • core: a declined edit is refused and leaves the baseline
  • CLI: a push refusal vs a failure (stderr lines pinned, failure before refusal); an unreachable wiki; a corrupt manifest for all four commands

Breaking each mapping fails a test:

unknown command -> 2: exit 1, 1 failed: TestRun
no credentials -> 2: exit 1, 2 failed: TestRun, TestLoginNeedsCredentials
pull wiki error -> 1: exit 1, 1 failed: TestPullFromAnUnreachableWikiIsAnEnvironmentFault
status error -> 1: exit 1, 1 failed: TestUnreadableTreeIsAnEnvironmentFault
page error -> 1: exit 1, 1 failed: TestPushExitTellsARefusalFromAFailure
refusal overrides failure: exit 1, 1 failed: TestPushExitTellsARefusalFromAFailure
tree unreadable -> 1: exit 1, 1 failed: TestUnreadableTreeIsAnEnvironmentFault
server error is a refusal: exit 1, 2 failed: TestPushExitTellsARefusalFromAFailure, TestRefusedTellsTheWikiDecliningFromTheWikiFailing
edit result not wrapped: exit 1, 1 failed: TestRefusedTellsTheWikiDecliningFromTheWikiFailing
core never refuses: exit 1, 3 failed: TestPushExitTellsARefusalFromAFailure, TestPushServerSideConflictLeavesBaseline, TestPushEditTheWikiDeclinesIsRefused

just check (gofmt, golangci-lint 0 issues, vet) and just test (go test -race ./...) pass. go vet -tags integration ./... passes; the Docker round trip runs in CI. docs/commands.md and the CHANGELOG (Unreleased) carry the new codes.

Closes #66

Following the ruling on #66, wikisync exits on the org table:

- usage errors exit 64, not 2
- an unreachable or failing wiki, missing credentials, a failed login,
  and a working tree or local file that can't be read or written exit
  4, not 1 or 2
- refusals stay 1: conflicts, skipped pages, an untracked title, a
  pull that wrote nothing, --max exceeded

push now tells the wiki declining an edit (mw.Refused: an API error
such as protectedpage or editconflict, or an edit result other than
Success) from the wiki or the connection failing (a server error, a
read-only or lagged wiki, a rate limit, a lost session, a transport
or HTTP-status failure). The first is a new `refused` line and exit
1; the second stays an `error` line and exits 4. A run with both
exits 4, since it didn't finish deciding.

An edit that lands but whose saved text can't be read back keeps
exit 0 with its warning, and a pull that matched nothing keeps 1.

The core test fake now answers a stale baserevid with the
editconflict API error the real wiki sends, so that case is refused.

BREAKING CHANGE: scripts branching on exit 2 for usage or on 1 for an
unreachable wiki, missing credentials or a failed login need updating.

Closes #66
@CameronBrooks11
CameronBrooks11 merged commit 680bb98 into main Nov 20, 2026
7 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/exit-codes branch November 20, 2026 03:34
CameronBrooks11 added a commit that referenced this pull request Nov 20, 2026
chore: bump version to 0.7.0

0.7.0 moves wikisync onto the heibench exit codes (#66, #69): usage
errors exit 64, environment faults exit 4, and push tells a refused
edit (1) from a failing wiki (4). Breaking for scripts that branch on
the old codes. `wikisync --version` prints 0.7.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exit codes differ from the heibench table: 2 is usage, an unreachable wiki is 1

1 participant