Skip to content

Commit

Permalink
Merge pull request #1351 from abyssparanoia/fix/error-handling-for-st…
Browse files Browse the repository at this point in the history
…acktrace

Fix/error handling for stacktrace
  • Loading branch information
abyssparanoia authored Dec 11, 2024
2 parents 45406fb + b054ccb commit 567c6f4
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 22 deletions.
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,6 @@ github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvK
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.25 h1:r67ps7oHCYnflpgDy2LZU0MAQtQbYIOqNNnqGO6xQkE=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.25/go.mod h1:GrGY+Q4fIokYLtjCVB/aFfCVL6hhGUFl8inD18fDalE=
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.47.1 h1:isjmZUmhAMzCLs38LnWVIKqWRSkItqZVGpdJowlmV/Y=
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.47.1/go.mod h1:U+GnB0KkXI5SgVMzW2J1FHMGbAiObr1XaIGZSMejLlI=
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.48.0 h1:0Ph3YCW0bkw5cZbH3MAWCNC5lbhnn0vTIX6UlVlXRnY=
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.48.0/go.mod h1:U+GnB0KkXI5SgVMzW2J1FHMGbAiObr1XaIGZSMejLlI=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 h1:iXtILhvDxB6kPvEXgsDhGaZCSC6LQET5ZHSdJozeI0Y=
Expand Down Expand Up @@ -2626,12 +2624,8 @@ google.golang.org/genproto v0.0.0-20230331144136-dcfb400f0633/go.mod h1:UUQDJDOl
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 h1:ToEetK57OidYuqD4Q5w+vfEnPvPpuTwedCNVohYJfNk=
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697/go.mod h1:JJrvXBWRZaFMxBufik1a4RpFw4HhgVtBBWQeQgUj2cc=
google.golang.org/genproto/googleapis/api v0.0.0-20241206012308-a4fef0638583 h1:v+j+5gpj0FopU0KKLDGfDo9ZRRpKdi5UBrCP0f76kuY=
google.golang.org/genproto/googleapis/api v0.0.0-20241206012308-a4fef0638583/go.mod h1:jehYqy3+AhJU9ve55aNOaSml7wUXjF9x6z2LcCfpAhY=
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 h1:CkkIfIt50+lT6NHAVoRYEyAvQGFM7xEwXUUywFvEb3Q=
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576/go.mod h1:1R3kvZ1dtP3+4p4d3G8uJ8rFk/fWlScl38vanWACI08=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 h1:IfdSdTcLFy4lqUQrQJLkLt1PB+AsqVz6lwkWPzWEz10=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 h1:8ZmaLZE4XWrtU3MyClkYqqtl6Oegr3235h7jxsDyqCY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand Down
4 changes: 2 additions & 2 deletions internal/domain/model/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func ValidateAssetPath(
path string,
) error {
if !assetType.Valid() {
return errors.AssetInvalidErr.
return errors.AssetInvalidErr.New().
WithDetail("asset_type is invalid").
WithValue("asset_type", assetType.String())
}
if !strings.HasPrefix(path, assetType.String()) {
return errors.AssetInvalidErr.
return errors.AssetInvalidErr.New().
WithDetail("path is invalid").
WithValue("path", path)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (c *CMD) CreateRootStaff(cmd *cobra.Command) error {
return errors.InternalErr.Wrap(err)
}
if password == "" {
return errors.InternalErr.WithDetail("password is required")
return errors.InternalErr.New().WithDetail("password is required")
}

if err := c.staffInteractor.CreateRoot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ func (r *staffAuthentication) VerifyIDToken(

jwtToken, err := jwt.ParseWithClaims(idToken, customClaims, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
return nil, errors.InvalidIDTokenErr.WithDetail("unexpected signing method")
return nil, errors.InvalidIDTokenErr.New().WithDetail("unexpected signing method")
}
kid, ok := token.Header["kid"].(string)
if !ok {
return nil, errors.InvalidIDTokenErr.WithDetail("kid header not found")
return nil, errors.InvalidIDTokenErr.New().WithDetail("kid header not found")
}
key, ok := r.publicKeySet.LookupKeyID(kid)
if !ok {
return nil, errors.InvalidIDTokenErr.WithDetail(fmt.Sprintf("key %v not found", kid))
return nil, errors.InvalidIDTokenErr.New().WithDetail(fmt.Sprintf("key %v not found", kid))
}
var tokenKey interface{}
if err := key.Raw(&tokenKey); err != nil {
return nil, errors.InvalidIDTokenErr.WithDetail("failed to create token key")
return nil, errors.InvalidIDTokenErr.New().WithDetail("failed to create token key")
}

return tokenKey, nil
Expand Down Expand Up @@ -181,7 +181,7 @@ func (r *staffAuthentication) CreateCustomToken(
ctx context.Context,
authUID string,
) (string, error) {
return "", errors.InternalErr.WithDetail("can not create custom token in cognito")
return "", errors.InternalErr.New().WithDetail("can not create custom token in cognito")
}

func (r *staffAuthentication) CreateIDToken(
Expand All @@ -203,7 +203,7 @@ func (r *staffAuthentication) CreateIDToken(
return "", errors.InternalErr.Wrap(err)
}
if res == nil || res.AuthenticationResult == nil || res.AuthenticationResult.IdToken == nil {
return "", errors.InternalErr.WithDetail("failed to auth")
return "", errors.InternalErr.New().WithDetail("failed to auth")
}

return *res.AuthenticationResult.IdToken, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/database/repository/staff.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r *staff) Get(
if err == sql.ErrNoRows && !query.OrFail {
return nil, nil
} else if err == sql.ErrNoRows {
return nil, errors.StaffNotFoundErr.
return nil, errors.StaffNotFoundErr.New().
WithDetail("staff is not found").
WithValue("query", query)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/database/repository/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (r *tenant) Get(
if err == sql.ErrNoRows && !query.OrFail {
return nil, nil
} else if err == sql.ErrNoRows {
return nil, errors.TenantNotFoundErr.
return nil, errors.TenantNotFoundErr.New().
WithDetail("tenant is not found").
WithValue("query", query)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (i *Authorization) UnaryServerInterceptor() grpc.UnaryServerInterceptor {
method := info.FullMethod
if strings.Contains(method, "AdminV1Service") {
if !ok || !staffSessionContext.StaffRole.Value().IsAdmin() {
return nil, errors.InvalidAdminRequestUserErr
return nil, errors.InvalidAdminRequestUserErr.New()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func SaveStaffSessionContext(
func RequireStaffSessionContext(ctx context.Context) (*model.StaffClaims, error) {
sctx, ok := GetStaffSessionContext(ctx)
if !ok {
return nil, errors.RequireStaffSessionErr
return nil, errors.RequireStaffSessionErr.New()
}
return sctx, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/spanner/repository/staff.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *staff) Get(
if !query.OrFail {
return nil, nil
} else {
return nil, errors.StaffNotFoundErr.
return nil, errors.StaffNotFoundErr.New().
WithDetail("staff is not found").
WithValue("query", query)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/spanner/repository/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (r *tenant) Get(
if !query.OrFail {
return nil, nil
} else {
return nil, errors.TenantNotFoundErr.
return nil, errors.TenantNotFoundErr.New().
WithDetail("tenant is not found").
WithValue("query", query)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/usecase/input/admin_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func (p *AdminCreateAssetPresignedURL) Validate() error {
return errors.RequestInvalidArgumentErr.Wrap(err)
}
if !p.AssetType.Valid() {
return errors.RequestInvalidArgumentErr.WithDetail(fmt.Sprintf("invalid asset type %s", p.AssetType))
return errors.RequestInvalidArgumentErr.New().
WithDetail(fmt.Sprintf("invalid asset type %s", p.AssetType))
}
return nil
}

0 comments on commit 567c6f4

Please sign in to comment.