Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add better error handling for init #4316

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions internal/namespaces/init/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func promptOrganizationID(ctx context.Context) (string, error) {
Prompt: "Choose your default organization ID",
ValidateFunc: func(s string) error {
if !validation.IsUUID(s) {
return errors.New("organization id is not a valid uuid")
return core.InvalidOrganizationIDError(s)
}
return nil
},
Expand All @@ -38,7 +38,7 @@ func promptManualProjectID(ctx context.Context, defaultProjectID string) (string
DefaultValueDoc: defaultProjectID,
ValidateFunc: func(s string) error {
if !validation.IsProjectID(s) {
return errors.New("organization id is not a valid uuid")
return core.InvalidProjectIDError(s)
}
return nil
},
Expand Down Expand Up @@ -146,7 +146,7 @@ func promptSecretKey(ctx context.Context) (string, error) {
if validation.IsSecretKey(s) {
return nil
}
return errors.New("invalid secret-key")
return core.InvalidSecretKeyError(s)
},
})
if err != nil {
Expand All @@ -158,7 +158,7 @@ func promptSecretKey(ctx context.Context) (string, error) {
return secret, nil

default:
return "", fmt.Errorf("invalid secret-key: '%v'", secret)
return "", core.InvalidSecretKeyError(secret)
}
}

Expand All @@ -175,7 +175,7 @@ func promptAccessKey(ctx context.Context) (string, error) {
},
ValidateFunc: func(s string) error {
if !validation.IsAccessKey(s) {
return errors.New("invalid access-key")
return core.InvalidAccessKeyError(s)
}

return nil
Expand All @@ -190,7 +190,7 @@ func promptAccessKey(ctx context.Context) (string, error) {
return key, nil

default:
return "", fmt.Errorf("invalid access-key: '%v'", key)
return "", core.InvalidAccessKeyError(key)
}
}

Expand All @@ -204,7 +204,7 @@ func promptDefaultZone(ctx context.Context) (scw.Zone, error) {
ValidateFunc: func(s string) error {
logger.Debugf("s: %v", s)
if !validation.IsZone(s) {
return errors.New("invalid zone")
return core.InvalidZoneError(s)
}
return nil
},
Expand Down
Loading