Skip to content

refactor(cloud/scale): Migrate final errors to typed vars#2774

Open
robaa12 wants to merge 6 commits intounikraft:stagingfrom
robaa12:issue-102-errors-pr1
Open

refactor(cloud/scale): Migrate final errors to typed vars#2774
robaa12 wants to merge 6 commits intounikraft:stagingfrom
robaa12:issue-102-errors-pr1

Conversation

@robaa12
Copy link
Copy Markdown
Contributor

@robaa12 robaa12 commented Apr 7, 2026

Prerequisite checklist

Description of changes

This PR is a scoped, file-by-file contribution toward #102 , limited to the cloud/scale command 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.go
  • internal/cli/kraft/cloud/scale/remove/remove.go
  • internal/cli/kraft/cloud/scale/get/get.go
  • internal/cli/kraft/cloud/scale/reset/reset.go
  • internal/cli/kraft/cloud/scale/initialize/initialize.go

What was changed:

  • Replaced final fmt.Errorf("...") returns with typed error vars where applicable.
  • Kept wrapped operational/contextual errors (...: %w) unchanged.
  • In some cases, preserved extra runtime context while wrapping typed errors (for future 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 fmt
    Notes:
  • Commits are intentionally split one file at a time to keep review and git bisect/blame clean.
  • This PR partially addresses Migrate all errors to constants #102.

robaa12 added 5 commits April 7, 2026 20:43
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>
@robaa12 robaa12 force-pushed the issue-102-errors-pr1 branch from da490cf to d006005 Compare April 7, 2026 18:44
Copy link
Copy Markdown
Member

@craciunoiuc craciunoiuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be moved to a separate file at on the cloud directory I think right?

@robaa12
Copy link
Copy Markdown
Contributor Author

robaa12 commented Apr 8, 2026

So you mean creating an errors.go file at the package level? I actually thought about doing that, but I saw this comment and went with a different approach:
#102 (comment)

Just to confirm I got it right the idea is to define all error constants in errors.go, then import and use them across the package?

@craciunoiuc
Copy link
Copy Markdown
Member

Yes

Though you won't import them if they are in the same package.

There are two possible options. I'm fine with both:

  • You populate the Errors at the top of each file and use them only in there
  • You populate them into an errors.go in every package

@robaa12
Copy link
Copy Markdown
Contributor Author

robaa12 commented Apr 8, 2026

I think the second approach is cleaner. I’ll start adding it to the cloud package and go from there.

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>
@robaa12
Copy link
Copy Markdown
Contributor Author

robaa12 commented Apr 8, 2026

Hey @craciunoiuc
I moved typed error declarations out of the command files and into package-level errors.go files for each touched cloud/scale subpackage:

  • internal/cli/kraft/cloud/scale/add/errors.go
  • internal/cli/kraft/cloud/scale/remove/errors.go
  • internal/cli/kraft/cloud/scale/get/errors.go
  • internal/cli/kraft/cloud/scale/reset/errors.go
  • internal/cli/kraft/cloud/scale/initialize/errors.go

I also removed the inline error variable blocks from the corresponding command files. Behavior remains unchanged, including %w wrapping and existing context where applicable.

Follow-up

For follow-up work, I plan to continue this migration in small, package-scoped PRs across the codebase.

@robaa12 robaa12 requested a review from craciunoiuc April 8, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🧊 Icebox

Development

Successfully merging this pull request may close these issues.

2 participants