Loading
refactor(cmdutils): share ParseID helper so invalid-ID errors name rejected value
Description
Related to #8691.
This MR introduces a shared ID-parsing helper in internal/cmdutils so that invalid numeric ID arguments produce clear, actionable error messages naming the rejected value.
Problem
Previously, eighteen commands printed a bare strconv error when an ID argument was not a valid number (e.g., strconv.ParseInt: parsing "abc": invalid syntax.). The descriptive string passed to cmdutils.WrapError(err, "invalid runner controller ID") was stored in ExitError.Details, but ExitError.Error() never renders Details, causing the user-facing explanation to be discarded.
Solution
- Added
cmdutils.ParseID(value, name string) (int64, error):- Parses
valueas a 64-bit integer. - Validates
id >= 1(rejecting 0, negative values, floats, and non-numeric strings). - Returns a structured error:
invalid <name>: "<value>". - Comprehensive unit tests added in
internal/cmdutils/parse_id_test.go.
- Parses
- Migrated
internal/commands/runnercontroller:- Updated 12 ID parsing call sites across 10 packages (
delete,get,scope/create,scope/delete,scope/list,token/create,token/list,token/revoke,token/rotate,update).
- Updated 12 ID parsing call sites across 10 packages (
- Migrated
internal/commands/runner:- Updated 6 ID parsing call sites across
assign,delete,jobs,managers,unassign, andupdate. - Tightened invalid-ID test assertions across
runnerandrunnercontrollercommands to check the fullinvalid <name>: "<value>"message.
- Updated 6 ID parsing call sites across
- Consolidated
container_registryanddeploy-tokencall sites:- Removed the redundant
internal/commands/container_registry/registryutils.ParseIDwrapper and its duplicate test; updated the 5container_registrycallers (repository/delete,repository/view,tag/delete,tag/list,tag/view) to callcmdutils.ParseIDdirectly. - Updated
internal/commands/deploy-token/get/get.goandinternal/commands/deploy-token/delete/delete.goto usecmdutils.ParseIDand removed the obsolete workaround comment.
- Removed the redundant
Related to #8691
Edited by AMIR