@@ -2,45 +2,48 @@ package dbos
22
33import "fmt"
44
5- // DBOSErrorCode represents the different types of DBOS errors
5+ // DBOSErrorCode represents the different types of errors that can occur in DBOS operations.
66type DBOSErrorCode int
77
88const (
9- ConflictingIDError DBOSErrorCode = iota + 1
10- InitializationError
11- WorkflowFunctionNotFound
12- NonExistentWorkflowError
13- ConflictingWorkflowError
14- WorkflowCancelled
15- UnexpectedStep
16- AwaitedWorkflowCancelled
17- ConflictingRegistrationError
18- WorkflowUnexpectedTypeError
19- WorkflowExecutionError
20- StepExecutionError
21- DeadLetterQueueError
22- MaxStepRetriesExceeded
9+ ConflictingIDError DBOSErrorCode = iota + 1 // Workflow ID conflicts or duplicate operations
10+ InitializationError // DBOS context initialization failures
11+ WorkflowFunctionNotFound // Workflow function not registered
12+ NonExistentWorkflowError // Referenced workflow does not exist
13+ ConflictingWorkflowError // Workflow with same ID already exists with different parameters
14+ WorkflowCancelled // Workflow was cancelled during execution
15+ UnexpectedStep // Step function mismatch during recovery (non-deterministic workflow)
16+ AwaitedWorkflowCancelled // A workflow being awaited was cancelled
17+ ConflictingRegistrationError // Attempting to register a workflow/queue that already exists
18+ WorkflowUnexpectedTypeError // Type mismatch in workflow input/output
19+ WorkflowExecutionError // General workflow execution error
20+ StepExecutionError // General step execution error
21+ DeadLetterQueueError // Workflow moved to dead letter queue after max retries
22+ MaxStepRetriesExceeded // Step exceeded maximum retry attempts
2323)
2424
25- // DBOSError is the unified error type for all DBOS errors
25+ // DBOSError is the unified error type for all DBOS operations.
26+ // It provides structured error information with context-specific fields
27+ // and error codes for programmatic handling.
2628type DBOSError struct {
27- Message string
28- Code DBOSErrorCode
29- StatusCode * int
30- IsBase bool // true for errors that shouldn't be caught by user code
31-
32- // Optional context fields - only set when relevant
33- WorkflowID string
34- DestinationID string
35- StepName string
36- QueueName string
37- DeduplicationID string
38- StepID int
39- ExpectedName string
40- RecordedName string
41- MaxRetries int
42- }
43-
29+ Message string // Human-readable error message
30+ Code DBOSErrorCode // Error type code for programmatic handling
31+ IsBase bool // Internal errors that shouldn't be caught by user code
32+
33+ // Optional context fields - only set when relevant to the error
34+ WorkflowID string // Associated workflow identifier
35+ DestinationID string // Target workflow identifier (for communication errors)
36+ StepName string // Step function name (for step errors)
37+ QueueName string // Queue name (for queue-related errors)
38+ DeduplicationID string // Deduplication identifier
39+ StepID int // Step sequence number
40+ ExpectedName string // Expected function name (for determinism errors)
41+ RecordedName string // Actually recorded function name (for determinism errors)
42+ MaxRetries int // Maximum retry limit (for retry-related errors)
43+ }
44+
45+ // Error returns a formatted error message including the error code.
46+ // This implements the standard Go error interface.
4447func (e * DBOSError ) Error () string {
4548 return fmt .Sprintf ("DBOS Error %d: %s" , int (e .Code ), e .Message )
4649}
0 commit comments