refactor(cloud/scale): Migrate final errors to typed vars#2774
refactor(cloud/scale): Migrate final errors to typed vars#2774robaa12 wants to merge 6 commits intounikraft:stagingfrom
Conversation
881fecd to
da490cf
Compare
Convert non-wrapped final errors in add command to file-local typed errors. Preserve detail by wrapping typed errors with %w where useful. Signed-off-by: robaa12 <arobaa23@gmail.com>
Convert non-wrapped final validation errors in remove command to file-local typed errors for future errors.Is matching. Signed-off-by: robaa12 <arobaa23@gmail.com>
Convert non-wrapped final validation error in get command to a file-local typed error for future errors.Is handling. Signed-off-by: robaa12 <arobaa23@gmail.com>
Convert non-wrapped final validation error in reset command to a file-local typed error for richer error checks later. Signed-off-by: robaa12 <arobaa23@gmail.com>
Convert non-wrapped final validation errors in initialize command to file-local typed errors. Keep contextual details on returned values. Signed-off-by: robaa12 <arobaa23@gmail.com>
da490cf to
d006005
Compare
craciunoiuc
left a comment
There was a problem hiding this comment.
These should be moved to a separate file at on the cloud directory I think right?
|
So you mean creating an Just to confirm I got it right the idea is to define all error constants in |
|
Yes Though you won't import them if they are in the same package. There are two possible options. I'm fine with both:
|
|
I think the second approach is cleaner. I’ll start adding it to the |
Move typed error declarations from command files into package- level errors.go files for each cloud/scale subpackage. This keeps command implementations focused while preserving existing error behavior and %w wrapping. Signed-off-by: robaa12 <arobaa23@gmail.com>
|
Hey @craciunoiuc
I also removed the inline error variable blocks from the corresponding command files. Behavior remains unchanged, including Follow-upFor follow-up work, I plan to continue this migration in small, package-scoped PRs across the codebase. |
Prerequisite checklist
Description of changes
This PR is a scoped, file-by-file contribution toward #102 , limited to the
cloud/scalecommand package.It converts non-wrapped final errors to file-local typed errors (
var Err... = errors.New(...)) in the following files:internal/cli/kraft/cloud/scale/add/add.gointernal/cli/kraft/cloud/scale/remove/remove.gointernal/cli/kraft/cloud/scale/get/get.gointernal/cli/kraft/cloud/scale/reset/reset.gointernal/cli/kraft/cloud/scale/initialize/initialize.goWhat was changed:
fmt.Errorf("...")returns with typed error vars where applicable....: %w) unchanged.errors.Is(...)checks).Validation:
go test ./internal/cli/kraft/cloud/scale/...go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.4 fmtNotes:
git bisect/blameclean.