@@ -117,92 +117,3 @@ func TestCronContextCancellationBeforeStart(t *testing.T) {
117117 t .Fatal ("Server failed to handle pre-cancelled context" )
118118 }
119119}
120-
121- // TestChainErrorHandling verifies that GetChain returns proper errors with context
122- func TestChainErrorHandling (t * testing.T ) {
123- t .Log ("=== Testing Chain Error Handling ===" )
124-
125- srv := newServer (t , "test" , func (b []byte , ctx JobCtx ) error {
126- return nil
127- })
128-
129- // Test 1: Get non-existent chain
130- _ , err := srv .GetChain (context .Background (), "non-existent-chain" )
131- if err == nil {
132- t .Fatal ("Expected error for non-existent chain, got nil" )
133- }
134- t .Logf ("✅ Non-existent chain error: %v" , err )
135-
136- // Test 2: Create a chain and verify normal operation first
137- job1 , _ := NewJob ("test" , []byte ("job1" ), JobOpts {})
138- job2 , _ := NewJob ("test" , []byte ("job2" ), JobOpts {})
139- chain , err := NewChain ([]Job {job1 , job2 }, ChainOpts {})
140- if err != nil {
141- t .Fatal ("Failed to create chain:" , err )
142- }
143-
144- chainID , err := srv .EnqueueChain (context .Background (), chain )
145- if err != nil {
146- t .Fatal ("Failed to enqueue chain:" , err )
147- }
148- t .Logf ("Created chain: %s" , chainID )
149-
150- // Test 3: Verify proper error context by testing with invalid job ID
151- // (This simulates what happens when job storage is corrupted or jobs are deleted)
152- chainMsg , err := srv .getChainMessage (context .Background (), chainID )
153- if err != nil {
154- t .Fatal ("Failed to get chain message:" , err )
155- }
156-
157- // Set an invalid job ID to test error handling
158- chainMsg .JobID = "definitely-non-existent-job-id-12345"
159- err = srv .setChainMessage (context .Background (), chainMsg )
160- if err != nil {
161- t .Fatal ("Failed to set modified chain message:" , err )
162- }
163-
164- // Try to get chain with invalid job reference - should get descriptive error
165- _ , err = srv .GetChain (context .Background (), chainID )
166- if err == nil {
167- t .Fatal ("Expected error for invalid job reference, got nil" )
168- }
169-
170- // Verify error contains helpful context for debugging
171- errorStr := err .Error ()
172- t .Logf ("✅ Invalid job reference error: %v" , err )
173-
174- // Check that error message contains key debugging information
175- requiredContexts := []string {
176- "failed to get current job" , // Action that failed
177- "definitely-non-existent-job-id" , // The problematic job ID
178- chainID , // The chain being processed
179- }
180-
181- for _ , context := range requiredContexts {
182- if ! stringContains (errorStr , context ) {
183- t .Errorf ("Error message missing expected context '%s' in: %s" , context , errorStr )
184- }
185- }
186-
187- t .Log ("✅ Error messages contain proper context for debugging" )
188- }
189-
190- // Helper function to check if string contains substring
191- func stringContains (s , substr string ) bool {
192- if len (substr ) > len (s ) {
193- return false
194- }
195- for i := 0 ; i <= len (s )- len (substr ); i ++ {
196- match := true
197- for j := 0 ; j < len (substr ); j ++ {
198- if s [i + j ] != substr [j ] {
199- match = false
200- break
201- }
202- }
203- if match {
204- return true
205- }
206- }
207- return false
208- }
0 commit comments