Skip to main content

update_exit_code

Function update_exit_code 

Source
pub fn update_exit_code(plan: &UpdatePlan) -> i32
Expand description

Computes the process exit code for a completed update run (spec §5’s exit-code table, as amended by S3 — see below).

0 if every item is Outcome::Applied, the plan was empty (nothing eligible), or every non-Applied item is a deliberate exclusion (Outcome::Skipped with reason SkipReason::NotRequested — a --package narrowing — Outcome::Skipped with reason SkipReason::IgnoreRule — a [update].ignore match — Outcome::Skipped with reason SkipReason::WithinFreshnessCooldown, issue #1525’s automatic, policy-driven pause rather than a failed fix attempt — not guaranteed to self-resolve: it clears only once a release survives long enough to age past the cooldown window without a newer release replacing it, so a package publishing at least once per window can stay skipped indefinitely (see SkipReason::WithinFreshnessCooldown’s own doc) — or Outcome::Skipped with reason SkipReason::OverlapsAnotherEdit: a genuinely overlapping edit dropped by crate::update::dedup_applied_items, not a failed fix attempt — the surviving edit at the same span already achieves the write (spec 075 fix-cycle finding: crate::update::plan_updates now calls dedup_applied_items on itself, per FR-015, making this variant reachable from default-mode update for the first time; leaving it out of this exemption list regressed a scenario that exited clean before that change). 1 if at least one item is Outcome::Skipped with reason SkipReason::NotSafelyEditable, Outcome::RequiresLockfileUpdate, or Outcome::Unfixable — these represent something the run wanted to fix but could not, unlike an operator-requested exclusion. 2 (execution error — parse/write/TOCTOU/symlink/offline-gate failures) is set by the caller before this function is ever reached, never by this function itself (FR-022 — a non-zero exit here never implies the working tree is unmodified: a mixed run can exit 1 with real edits already on disk).

S3 amendment: spec.md’s own exit-code table (§5) originally listed any skip, including NotRequested/IgnoreRule, under exit 1 — directly contradicting US-004’s stated acceptance criterion (“tokio is skipped, reported skipped (ignore-rule), and the run still exits 0 if every other selected dependency was applied”). This function implements US-004’s reading: an operator explicitly asking to skip something is not a failure. spec.md §5 and book/src/cli.md are updated to match.

§Examples

use deps_cli::exit::{EXIT_CLEAN, EXIT_POLICY_VIOLATION, update_exit_code};
use deps_cli::update::UpdatePlan;

assert_eq!(update_exit_code(&UpdatePlan::default()), EXIT_CLEAN);