Skip to content

Commit 662923c

Browse files
committed
Refactor error handlers to use dedicated global hook
1 parent 8cb9c2a commit 662923c

File tree

7 files changed

+89
-97
lines changed

7 files changed

+89
-97
lines changed

testing/Project/Sources/Classes/TestRunner.4dm

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ Function _prepareErrorHandlingStorage()
3131
Else
3232
Storage:C1525.testErrors.clear()
3333
End if
34-
35-
If (Storage:C1525.testErrorHandlerProcesses=Null:C1517)
36-
Storage:C1525.testErrorHandlerProcesses:=New shared collection:C1527
37-
Else
38-
Storage:C1525.testErrorHandlerProcesses.clear()
39-
End if
4034
End use
4135

4236
Function _runInternal()
@@ -70,7 +64,6 @@ Function _installErrorHandler() : Object
7064
var $previousGlobalHandler : Text
7165
var $shouldInstallLocal : Boolean
7266
var $shouldInstallGlobal : Boolean
73-
var $currentProcess : Integer
7467

7568
$previousErrorHandler:=Method called on error:C704
7669
$shouldInstallLocal:=($previousErrorHandler#"TestErrorHandler")
@@ -80,34 +73,24 @@ Function _installErrorHandler() : Object
8073
End if
8174

8275
$previousGlobalHandler:=Method called on error:C704(1)
83-
$shouldInstallGlobal:=($previousGlobalHandler#"TestErrorHandler")
84-
85-
$currentProcess:=Current process:C322
86-
87-
TestErrorHandlerRegisterProcess($currentProcess)
76+
$shouldInstallGlobal:=($previousGlobalHandler#"TestGlobalErrorHandler")
8877

8978
If ($shouldInstallGlobal)
90-
ON ERR CALL:C155("TestErrorHandler"; 1)
79+
ON ERR CALL:C155("TestGlobalErrorHandler"; 1)
9180
End if
9281

9382
return New object:C1471(\
9483
"previousHandler"; $previousErrorHandler; \
9584
"installedLocalHandler"; $shouldInstallLocal; \
9685
"previousGlobalHandler"; $previousGlobalHandler; \
97-
"installedGlobalHandler"; $shouldInstallGlobal; \
98-
"processNumber"; $currentProcess\
86+
"installedGlobalHandler"; $shouldInstallGlobal\
9987
)
10088

10189
Function _restoreErrorHandler($handlerState : Object)
10290
If ($handlerState=Null:C1517)
10391
return
10492
End if
10593

106-
var $processNumber : Integer
107-
$processNumber:=$handlerState.processNumber || Current process:C322
108-
109-
TestErrorHandlerUnregister($processNumber)
110-
11194
If (Bool:C1537($handlerState.installedLocalHandler))
11295
var $previousErrorHandler : Text
11396
$previousErrorHandler:=$handlerState.previousHandler
@@ -288,7 +271,7 @@ Function _drainGlobalErrorsFromStorage() : Collection
288271
var $context : Text
289272
$context:=$error.context || ""
290273

291-
If ($context#"local")
274+
If ($context="global")
292275
$globalErrors.push(OB Copy:C1225($error))
293276
Storage:C1525.testErrors.remove($index)
294277
End if

testing/Project/Sources/Classes/_ErrorHandlingTest.4dm

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ Function test_error_handler_initialization($t : cs:C1710.Testing)
1111
$t.assert.isNotNull($t; Storage:C1525.testErrors; "Error storage should be initialized")
1212
$t.assert.areEqual($t; Is collection:K8:32; Value type:C1509(Storage:C1525.testErrors); "Error storage should be a collection")
1313

14-
// Ensure local process tracking is available
15-
$t.assert.isNotNull($t; Storage:C1525.testErrorHandlerProcesses; "Process tracking should be initialized")
16-
$t.assert.areEqual($t; Is collection:K8:32; Value type:C1509(Storage:C1525.testErrorHandlerProcesses); "Process tracking should be a collection")
17-
1814
Function test_error_information_structure($t : cs:C1710.Testing)
1915

2016
// Create a mock error info structure like the error handler would
@@ -94,40 +90,51 @@ Function test_global_error_collection($t : cs:C1710.Testing)
9490
$t.assert.areEqual($t; 0; Storage:C1525.testErrors.length; "Global errors should be drained from storage")
9591
End use
9692

97-
Function test_register_process_tracking($t : cs:C1710.Testing)
93+
Function test_local_errors_remain_in_storage($t : cs:C1710.Testing)
9894

99-
var $runner : cs:C1710.TestRunner
100-
$runner:=cs:C1710.TestRunner.new()
101-
$runner._prepareErrorHandlingStorage()
95+
Use (Storage:C1525)
96+
Storage:C1525.testErrors:=New shared collection:C1527
97+
End use
10298

103-
var $processNumber : Integer
104-
$processNumber:=98765
99+
var $localError : Object
100+
$localError:=New object:C1471(\
101+
"code"; 123; \
102+
"text"; "LocalFailure"; \
103+
"method"; "DoLocalThing"; \
104+
"line"; 21; \
105+
"timestamp"; Milliseconds:C459; \
106+
"processNumber"; 7; \
107+
"context"; "local"; \
108+
"isLocal"; True:C214\
109+
)
105110

106-
TestErrorHandlerRegisterProcess($processNumber)
111+
var $globalError : Object
112+
$globalError:=New object:C1471(\
113+
"code"; 456; \
114+
"text"; "GlobalFailure"; \
115+
"method"; "DoGlobalThing"; \
116+
"line"; 33; \
117+
"timestamp"; Milliseconds:C459; \
118+
"processNumber"; 42; \
119+
"context"; "global"; \
120+
"isLocal"; False:C215\
121+
)
107122

108-
Use (Storage:C1525.testErrorHandlerProcesses)
109-
$t.assert.isTrue($t; Storage:C1525.testErrorHandlerProcesses.indexOf($processNumber)>=0; "Should register process for local error tracking")
123+
Use (Storage:C1525.testErrors)
124+
Storage:C1525.testErrors.push(OB Copy:C1225($localError; ck shared:K85:29))
125+
Storage:C1525.testErrors.push(OB Copy:C1225($globalError; ck shared:K85:29))
110126
End use
111127

112-
// Registering again should not duplicate entries
113-
TestErrorHandlerRegisterProcess($processNumber)
114-
115-
Use (Storage:C1525.testErrorHandlerProcesses)
116-
var $occurrences : Integer
117-
$occurrences:=0
118-
var $index : Integer
119-
For ($index; 0; Storage:C1525.testErrorHandlerProcesses.length-1)
120-
If (Storage:C1525.testErrorHandlerProcesses[$index]=$processNumber)
121-
$occurrences+=1
122-
End if
123-
End for
124-
$t.assert.areEqual($t; 1; $occurrences; "Process should only be tracked once")
125-
End use
128+
var $runner : cs:C1710.TestRunner
129+
$runner:=cs:C1710.TestRunner.new()
126130

127-
TestErrorHandlerUnregister($processNumber)
131+
$runner._captureGlobalErrors()
132+
133+
$t.assert.areEqual($t; 1; $runner.results.globalErrorCount; "Runner should capture one global error")
128134

129-
Use (Storage:C1525.testErrorHandlerProcesses)
130-
$t.assert.isFalse($t; Storage:C1525.testErrorHandlerProcesses.indexOf($processNumber)>=0; "Should remove process from tracking after unregister")
135+
Use (Storage:C1525.testErrors)
136+
$t.assert.areEqual($t; 1; Storage:C1525.testErrors.length; "Local errors should remain in storage")
137+
$t.assert.areEqual($t; "local"; Storage:C1525.testErrors[0].context; "Remaining error should be local")
131138
End use
132139

133140
Function test_testing_context_properties($t : cs:C1710.Testing)

testing/Project/Sources/Methods/ParallelTestWorker.4dm

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ Case of
4242
End if
4343
End use
4444

45-
TestErrorHandlerRegisterProcess(Current process:C322)
46-
4745
Use ($handlerState)
4846
If (Not:C34($handlerState.installed))
4947
$handlerState.previousHandler:=$previousErrorHandler
@@ -169,8 +167,6 @@ Case of
169167
End if
170168
End use
171169

172-
TestErrorHandlerUnregister(Current process:C322)
173-
174170
If ($handlerState#Null:C1517)
175171
var $shouldRestore : Boolean
176172
var $previousHandler : Text

testing/Project/Sources/Methods/TestErrorHandler.4dm

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
//%attributes = {}
22
// TestErrorHandler
3-
// Global error handler for the testing framework
3+
// Local error handler for the testing framework
44
// Captures runtime errors and records minimal metadata for later reporting
55

66
var $errorCode : Integer
77
var $errorText : Text
88
var $errorMethod : Text
99
var $errorLine : Integer
1010
var $processNumber : Integer
11-
var $isLocalProcess : Boolean
1211
var $context : Text
12+
var $isLocalProcess : Boolean
1313

1414
$errorCode:=Error
1515
$errorText:=Error method
1616
$errorMethod:=Error formula
1717
$errorLine:=Error line
1818
$processNumber:=Current process:C322
19-
$isLocalProcess:=False:C215
20-
21-
If (Storage:C1525.testErrorHandlerProcesses#Null:C1517)
22-
Use (Storage:C1525.testErrorHandlerProcesses)
23-
If (Storage:C1525.testErrorHandlerProcesses.indexOf($processNumber)>=0)
24-
$isLocalProcess:=True:C214
25-
$context:="local"
26-
End if
27-
End use
28-
End if
29-
30-
$context:=Choose:C955($isLocalProcess; "local"; "global")
19+
$context:="local"
20+
$isLocalProcess:=True:C214
3121

3222
// Store error information in Storage for later retrieval
3323
If (Storage:C1525.testErrors=Null:C1517)

testing/Project/Sources/Methods/TestErrorHandlerRegisterProcess.4dm

Lines changed: 0 additions & 15 deletions
This file was deleted.

testing/Project/Sources/Methods/TestErrorHandlerUnregister.4dm

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//%attributes = {}
2+
// TestGlobalErrorHandler
3+
// Global error handler for the testing framework
4+
// Captures runtime errors from processes without the local test handler
5+
6+
var $errorCode : Integer
7+
var $errorText : Text
8+
var $errorMethod : Text
9+
var $errorLine : Integer
10+
var $processNumber : Integer
11+
var $context : Text
12+
var $isLocalProcess : Boolean
13+
14+
$errorCode:=Error
15+
$errorText:=Error method
16+
$errorMethod:=Error formula
17+
$errorLine:=Error line
18+
$processNumber:=Current process:C322
19+
$context:="global"
20+
$isLocalProcess:=False:C215
21+
22+
If (Storage:C1525.testErrors=Null:C1517)
23+
Use (Storage:C1525)
24+
Storage:C1525.testErrors:=New shared collection:C1527
25+
End use
26+
End if
27+
28+
var $errorInfo : Object
29+
$errorInfo:=New object:C1471(\
30+
"code"; $errorCode; \
31+
"text"; $errorText; \
32+
"method"; $errorMethod; \
33+
"line"; $errorLine; \
34+
"timestamp"; Milliseconds:C459; \
35+
"processNumber"; $processNumber; \
36+
"context"; $context; \
37+
"isLocal"; $isLocalProcess\
38+
)
39+
40+
Use (Storage:C1525.testErrors)
41+
Storage:C1525.testErrors.push(OB Copy:C1225($errorInfo; ck shared:K85:29))
42+
End use
43+
44+
// Allow execution to continue so the runner can report the failure

0 commit comments

Comments
 (0)