mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? <!-- Describe what has changed in this PR --> Clean up errors in delete namespace workflows: 1. Use `FailedPrecondition` instead of `InvalidArgument` where it makes more sense. 2. Add helpers to construct `ApplicationError`s of different type. 3. Remove `unable to execute activity` error which was wrongly used in many places. 4. Few minor cleanups. ## Why? <!-- Tell your future self why have you made these changes --> Simplify and unify error handling in delete namespace workflows. ## How did you test it? <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> Modified tests. Manual runs. ## Potential risks <!-- Assuming the worst case, what can be broken when deploying this change to production? --> No risks. ## Documentation <!-- Have you made sure this change doesn't falsify anything currently stated in `docs/`? If significant new behavior is added, have you described that in `docs/`? --> No. ## Is hotfix candidate? <!-- Is this PR a hotfix candidate or does it require a notification to be sent to the broader community? (Yes/No) --> No.
79 lines
3.0 KiB
Go
79 lines
3.0 KiB
Go
// The MIT License
|
|
//
|
|
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
|
|
//
|
|
// Copyright (c) 2020 Uber Technologies, Inc.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
package errors
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
commonpb "go.temporal.io/api/common/v1"
|
|
"go.temporal.io/api/serviceerror"
|
|
"go.temporal.io/sdk/temporal"
|
|
)
|
|
|
|
const (
|
|
InvalidArgumentErrType = "InvalidArgument"
|
|
FailedPreconditionErrType = "FailedPrecondition"
|
|
ExecutionsStillExistErrType = "ExecutionsStillExist"
|
|
NoProgressErrType = "NoProgress"
|
|
NotDeletedExecutionsStillExistErrType = "NotDeletedExecutionsStillExist"
|
|
)
|
|
|
|
func NewInvalidArgument(message string, cause error) error {
|
|
return temporal.NewNonRetryableApplicationError(message, InvalidArgumentErrType, cause, nil)
|
|
}
|
|
|
|
func NewFailedPrecondition(message string, cause error) error {
|
|
return temporal.NewNonRetryableApplicationError(message, FailedPreconditionErrType, cause, nil)
|
|
}
|
|
|
|
func NewExecutionsStillExist(count int) error {
|
|
return temporal.NewApplicationError(fmt.Sprintf("%d executions are still exist", count), ExecutionsStillExistErrType, count)
|
|
}
|
|
|
|
func NewNoProgress(count int) error {
|
|
return temporal.NewNonRetryableApplicationError(fmt.Sprintf("no progress was made: %d executions are still exist", count), NoProgressErrType, nil, count)
|
|
}
|
|
|
|
func NewNotDeletedExecutionsStillExist(count int) error {
|
|
return temporal.NewNonRetryableApplicationError(fmt.Sprintf("%d not deleted executions are still exist", count), NotDeletedExecutionsStillExistErrType, nil, count)
|
|
}
|
|
|
|
func ToServiceError(err error, workflowID, runID string) error {
|
|
var appErr *temporal.ApplicationError
|
|
if errors.As(err, &appErr) {
|
|
switch appErr.Type() {
|
|
case InvalidArgumentErrType:
|
|
return serviceerror.NewInvalidArgument(appErr.Message())
|
|
case FailedPreconditionErrType:
|
|
return serviceerror.NewFailedPrecondition(appErr.Message())
|
|
}
|
|
}
|
|
return serviceerror.NewSystemWorkflow(
|
|
&commonpb.WorkflowExecution{WorkflowId: workflowID, RunId: runID},
|
|
err,
|
|
)
|
|
}
|