Skip to content

Commit

Permalink
add throw without reason
Browse files Browse the repository at this point in the history
  • Loading branch information
mscno committed Mar 23, 2024
1 parent e8ff6b0 commit e87c7a4
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 13 deletions.
7 changes: 6 additions & 1 deletion already_exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type AlreadyExistsError struct {
*Zerror
}

func ThrowAlreadyExists(action, kind, name, reason string) error {
func ThrowAlreadyExists(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &AlreadyExistsError{CreateZerror(nil, AlreadyExistsId, message)}
}

func ThrowAlreadyExistsr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &AlreadyExistsError{CreateZerror(nil, AlreadyExistsId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion deadline_exceeded.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type DeadlineExceededError struct {
*Zerror
}

func ThrowDeadlineExceeded(action, kind, name, reason string) error {
func ThrowDeadlineExceeded(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &DeadlineExceededError{CreateZerror(nil, DeadlineExceededId, message)}
}

func ThrowDeadlineExceededr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &DeadlineExceededError{CreateZerror(nil, DeadlineExceededId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion failed_precondition.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type FailedPreconditionError struct {
*Zerror
}

func ThrowFailedPrecondition(action, kind, name, reason string) error {
func ThrowFailedPrecondition(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &FailedPreconditionError{CreateZerror(nil, FailedPreconditionId, message)}
}

func ThrowFailedPreconditionr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &FailedPreconditionError{CreateZerror(nil, FailedPreconditionId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion generate/error.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type {{.ErrorName}}Error struct {
*Zerror
}

func Throw{{.ErrorName}}(action, kind, name, reason string) error {
func Throw{{.ErrorName}}(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &{{.ErrorName}}Error{CreateZerror(nil, {{.ErrorName}}Id, message)}
}

func Throw{{.ErrorName}}r(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &{{.ErrorName}}Error{CreateZerror(nil, {{.ErrorName}}Id, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type InternalError struct {
*Zerror
}

func ThrowInternal(action, kind, name, reason string) error {
func ThrowInternal(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &InternalError{CreateZerror(nil, InternalId, message)}
}

func ThrowInternalr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &InternalError{CreateZerror(nil, InternalId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion invalid_argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type InvalidArgumentError struct {
*Zerror
}

func ThrowInvalidArgument(action, kind, name, reason string) error {
func ThrowInvalidArgument(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &InvalidArgumentError{CreateZerror(nil, InvalidArgumentId, message)}
}

func ThrowInvalidArgumentr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &InvalidArgumentError{CreateZerror(nil, InvalidArgumentId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion not_found.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type NotFoundError struct {
*Zerror
}

func ThrowNotFound(action, kind, name, reason string) error {
func ThrowNotFound(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &NotFoundError{CreateZerror(nil, NotFoundId, message)}
}

func ThrowNotFoundr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &NotFoundError{CreateZerror(nil, NotFoundId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion permission_denied.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type PermissionDeniedError struct {
*Zerror
}

func ThrowPermissionDenied(action, kind, name, reason string) error {
func ThrowPermissionDenied(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &PermissionDeniedError{CreateZerror(nil, PermissionDeniedId, message)}
}

func ThrowPermissionDeniedr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &PermissionDeniedError{CreateZerror(nil, PermissionDeniedId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion resource_exhausted.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type ResourceExhaustedError struct {
*Zerror
}

func ThrowResourceExhausted(action, kind, name, reason string) error {
func ThrowResourceExhausted(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &ResourceExhaustedError{CreateZerror(nil, ResourceExhaustedId, message)}
}

func ThrowResourceExhaustedr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &ResourceExhaustedError{CreateZerror(nil, ResourceExhaustedId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion unauthenticated.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type UnauthenticatedError struct {
*Zerror
}

func ThrowUnauthenticated(action, kind, name, reason string) error {
func ThrowUnauthenticated(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &UnauthenticatedError{CreateZerror(nil, UnauthenticatedId, message)}
}

func ThrowUnauthenticatedr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &UnauthenticatedError{CreateZerror(nil, UnauthenticatedId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion unavailable.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type UnavailableError struct {
*Zerror
}

func ThrowUnavailable(action, kind, name, reason string) error {
func ThrowUnavailable(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &UnavailableError{CreateZerror(nil, UnavailableId, message)}
}

func ThrowUnavailabler(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &UnavailableError{CreateZerror(nil, UnavailableId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion unimplemented.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type UnimplementedError struct {
*Zerror
}

func ThrowUnimplemented(action, kind, name, reason string) error {
func ThrowUnimplemented(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &UnimplementedError{CreateZerror(nil, UnimplementedId, message)}
}

func ThrowUnimplementedr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &UnimplementedError{CreateZerror(nil, UnimplementedId, message)}
}
Expand Down
7 changes: 6 additions & 1 deletion unknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type UnknownError struct {
*Zerror
}

func ThrowUnknown(action, kind, name, reason string) error {
func ThrowUnknown(action, kind, name string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s'", action, name, kind)
return &UnknownError{CreateZerror(nil, UnknownId, message)}
}

func ThrowUnknownr(action, kind, name, reason string) error {
message := fmt.Sprintf("cannot %s '%s' of kind '%s': %s", action, name, kind, reason)
return &UnknownError{CreateZerror(nil, UnknownId, message)}
}
Expand Down

0 comments on commit e87c7a4

Please sign in to comment.