mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package serviceerror
|
|
|
|
import (
|
|
"go.temporal.io/api/serviceerror"
|
|
errordetailsspb "github.com/hanzoai/tasks/api/errordetails/v1"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// FromStatus converts gRPC status to service error.
|
|
func FromStatus(st *status.Status) error {
|
|
if st == nil || st.Code() == codes.OK {
|
|
return nil
|
|
}
|
|
|
|
errDetails := extractErrorDetails(st)
|
|
|
|
switch st.Code() {
|
|
case codes.InvalidArgument:
|
|
switch errDetails := errDetails.(type) {
|
|
case *errordetailsspb.CurrentBranchChangedFailure:
|
|
return newCurrentBranchChanged(st, errDetails)
|
|
}
|
|
case codes.AlreadyExists:
|
|
switch errDetails.(type) {
|
|
case *errordetailsspb.TaskAlreadyStartedFailure:
|
|
return newTaskAlreadyStarted(st)
|
|
}
|
|
case codes.Aborted:
|
|
switch errDetails := errDetails.(type) {
|
|
case *errordetailsspb.ShardOwnershipLostFailure:
|
|
return newShardOwnershipLost(st, errDetails)
|
|
case *errordetailsspb.RetryReplicationFailure:
|
|
return newRetryReplication(st, errDetails)
|
|
case *errordetailsspb.SyncStateFailure:
|
|
return newSyncState(st, errDetails)
|
|
}
|
|
case codes.Unavailable:
|
|
switch errDetails.(type) {
|
|
case *errordetailsspb.StickyWorkerUnavailableFailure:
|
|
return newStickyWorkerUnavailable(st)
|
|
}
|
|
case codes.FailedPrecondition:
|
|
switch errDetails.(type) {
|
|
case *errordetailsspb.ObsoleteDispatchBuildIdFailure:
|
|
return newObsoleteDispatchBuildId(st)
|
|
case *errordetailsspb.ObsoleteMatchingTaskFailure:
|
|
return newObsoleteMatchingTask(st)
|
|
case *errordetailsspb.ActivityStartDuringTransitionFailure:
|
|
return newActivityStartDuringTransition(st)
|
|
}
|
|
}
|
|
|
|
return serviceerror.FromStatus(st)
|
|
}
|
|
|
|
func extractErrorDetails(st *status.Status) any {
|
|
details := st.Details()
|
|
if len(details) > 0 {
|
|
return details[0]
|
|
}
|
|
|
|
return nil
|
|
}
|