Skip to content

Commit 0244601

Browse files
authored
fix: add better error handling for init (#4316)
1 parent ff7cb81 commit 0244601

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

internal/namespaces/init/prompt.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func promptOrganizationID(ctx context.Context) (string, error) {
2222
Prompt: "Choose your default organization ID",
2323
ValidateFunc: func(s string) error {
2424
if !validation.IsUUID(s) {
25-
return errors.New("organization id is not a valid uuid")
25+
return core.InvalidOrganizationIDError(s)
2626
}
2727
return nil
2828
},
@@ -38,7 +38,7 @@ func promptManualProjectID(ctx context.Context, defaultProjectID string) (string
3838
DefaultValueDoc: defaultProjectID,
3939
ValidateFunc: func(s string) error {
4040
if !validation.IsProjectID(s) {
41-
return errors.New("organization id is not a valid uuid")
41+
return core.InvalidProjectIDError(s)
4242
}
4343
return nil
4444
},
@@ -146,7 +146,7 @@ func promptSecretKey(ctx context.Context) (string, error) {
146146
if validation.IsSecretKey(s) {
147147
return nil
148148
}
149-
return errors.New("invalid secret-key")
149+
return core.InvalidSecretKeyError(s)
150150
},
151151
})
152152
if err != nil {
@@ -158,7 +158,7 @@ func promptSecretKey(ctx context.Context) (string, error) {
158158
return secret, nil
159159

160160
default:
161-
return "", fmt.Errorf("invalid secret-key: '%v'", secret)
161+
return "", core.InvalidSecretKeyError(secret)
162162
}
163163
}
164164

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

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

192192
default:
193-
return "", fmt.Errorf("invalid access-key: '%v'", key)
193+
return "", core.InvalidAccessKeyError(key)
194194
}
195195
}
196196

@@ -204,7 +204,7 @@ func promptDefaultZone(ctx context.Context) (scw.Zone, error) {
204204
ValidateFunc: func(s string) error {
205205
logger.Debugf("s: %v", s)
206206
if !validation.IsZone(s) {
207-
return errors.New("invalid zone")
207+
return core.InvalidZoneError(s)
208208
}
209209
return nil
210210
},

0 commit comments

Comments
 (0)