Skip to content

Commit 84c7896

Browse files
authored
fix: load service by name (#136)
* fix: load service by name * fix linter
1 parent 879dada commit 84c7896

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

src/cmd/scope/scopeService.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ func (s *service) LoadSelectedScope(ctx context.Context, _ *cmdBuilder.Cmd, cmdD
3636
if serviceIdOrName, exists := cmdData.Args[ServiceArgName]; exists {
3737
service, err = repository.GetServiceByIdOrName(ctx, cmdData.RestApiClient, cmdData.Project.ID, serviceIdOrName[0])
3838
if err != nil {
39-
return errorsx.Convert(
40-
err,
41-
errorsx.ConvertInvalidUserInput("id", i18n.T(i18n.ErrorInvalidServiceIdOrName)),
42-
)
39+
return err
4340
}
4441
}
4542

src/cmd/servicePush.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ func servicePushCmd() *cmdBuilder.Cmd {
149149
},
150150
body.PutAppVersionBuildAndDeploy{
151151
ZeropsYaml: types.MediumText(configContent),
152-
Source: types.NewStringNull("CLI"),
153152
},
154153
)
155154
if err != nil {

src/entity/repository/service.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import (
55

66
"github.com/zeropsio/zcli/src/entity"
77
"github.com/zeropsio/zcli/src/errorsx"
8+
"github.com/zeropsio/zcli/src/i18n"
89
"github.com/zeropsio/zcli/src/zeropsRestApiClient"
910
"github.com/zeropsio/zerops-go/dto/input/body"
1011
"github.com/zeropsio/zerops-go/dto/input/path"
1112
"github.com/zeropsio/zerops-go/dto/output"
13+
"github.com/zeropsio/zerops-go/errorCode"
1214
"github.com/zeropsio/zerops-go/types"
1315
"github.com/zeropsio/zerops-go/types/uuid"
1416
)
@@ -21,15 +23,21 @@ func GetServiceByIdOrName(
2123
) (*entity.Service, error) {
2224
service, err := GetServiceById(ctx, restApiClient, uuid.ServiceStackId(serviceIdOrName))
2325
if err != nil {
24-
if errorsx.IsUserError(err) {
26+
if errorsx.Check(err,
27+
errorsx.CheckErrorCode(errorCode.InvalidUserInput),
28+
errorsx.CheckErrorCode(errorCode.ServiceStackNotFound),
29+
) {
2530
service, err = GetServiceByName(ctx, restApiClient, projectId, types.String(serviceIdOrName))
2631
if err != nil {
27-
return nil, err
32+
return nil, errorsx.Convert(
33+
err,
34+
errorsx.ConvertErrorCode(errorCode.ServiceStackNotFound, i18n.T(i18n.ErrorServiceNotFound, serviceIdOrName)),
35+
)
2836
}
2937
}
3038
}
3139

32-
return service, err
40+
return service, nil
3341
}
3442

3543
func GetServiceById(

src/errorsx/userError.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ func NewUserError(message string, previous error) *UserError {
1616
}
1717
}
1818

19-
func IsUserError(err error) bool {
20-
return AsUserError(err) != nil
21-
}
22-
2319
func AsUserError(err error) *UserError {
2420
var userError *UserError
2521
if errors.As(err, &userError) {

src/i18n/en.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,5 @@ more info: https://docs.zerops.io/documentation/cli/authorization.html`,
232232
ErrorInvalidProjectId: "Invalid project ID [%s]",
233233
ErrorInvalidScopedProjectId: "Invalid ID of the scoped project [%s], select a different project using `zcli scope project` command.",
234234
ErrorInvalidServiceId: "Invalid service ID [%s]",
235-
ErrorInvalidServiceIdOrName: "Invalid service ID or name [%s]",
235+
ErrorServiceNotFound: "Service [%s] not found",
236236
}

src/i18n/i18n.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,5 @@ const (
242242
ErrorInvalidProjectId = "ErrorInvalidProjectId"
243243
ErrorInvalidScopedProjectId = "ErrorInvalidScopedProjectId"
244244
ErrorInvalidServiceId = "ErrorInvalidServiceId"
245-
ErrorInvalidServiceIdOrName = "ErrorInvalidServiceIdOrName"
245+
ErrorServiceNotFound = "ErrorServiceNotFound"
246246
)

0 commit comments

Comments
 (0)