Skip to content

Commit d520974

Browse files
committed
Update changelog and enhance error handling with traceback support
1 parent 7393cb5 commit d520974

File tree

8 files changed

+78
-19
lines changed

8 files changed

+78
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Fix a regression in DTL to display sub-objects
1111

1212
### Changed
13-
- Cahnge debugger settings to be prefixed with `%` to avoid conflict with other settings
13+
- Change debugger settings to be prefixed with `%` to avoid conflict with other settings
1414

1515
### Added
1616
- Improve upgrade compatibility with 3.4.0 (pre-debugger)
17+
- Add `%traceback` setting to enable or disable traceback in message log
1718

1819
## [3.4.2] - 2025-05-2
1920
### Fixed

src/iop/cls/IOP/BusinessOperation.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Method OnMessage(
1515
try {
1616
set response = ..%class."_dispatch_on_message"(request)
1717
} catch ex {
18-
set tSC = ex.AsStatus()
18+
set tSC = ..DisplayTraceback(ex)
1919
}
2020
quit tSC
2121
}
@@ -27,7 +27,7 @@ Method OnKeepalive(pStatus As %Status = {$$$OK}) As %Status
2727
$$$ThrowOnError(##super(pStatus))
2828
do ..%class."on_keepalive"()
2929
} catch ex {
30-
set tSC = ex.AsStatus()
30+
set tSC = ..DisplayTraceback(ex)
3131
}
3232
quit tSC
3333
}

src/iop/cls/IOP/BusinessProcess.cls

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ Method dispatchSendRequestAsync(
3232
completionKey,
3333
description)
3434
{
35-
set tSC = ..SendRequestAsync(target,request,responseRequired,completionKey,description)
36-
if $$$ISERR(tSC) throw ##class(%Exception.StatusException).CreateFromStatus(tSC)
35+
Try {
36+
$$$ThrowOnError(..SendRequestAsync(target,request,responseRequired,completionKey,description))
37+
}
38+
Catch ex {
39+
set tSC = ..DisplayTraceback(ex)
40+
}
41+
3742
quit
3843
}
3944

@@ -45,7 +50,7 @@ Method OnRequest(
4550
try {
4651
set response = ..%class."_dispatch_on_request"($this,request)
4752
} catch ex {
48-
set tSC = ex.AsStatus()
53+
set tSC = ..DisplayTraceback(ex)
4954
}
5055
quit tSC
5156
}
@@ -62,7 +67,7 @@ Method OnResponse(
6267
try {
6368
set response = ..%class."_dispatch_on_response"($this,request,response,callRequest,callResponse,pCompletionKey)
6469
} catch ex {
65-
set tSC = ex.AsStatus()
70+
set tSC = ..DisplayTraceback(ex)
6671
}
6772
quit tSC
6873
}
@@ -75,7 +80,7 @@ Method OnComplete(
7580
try {
7681
set response = ..%class."_dispatch_on_complete"($this,request,response)
7782
} catch ex {
78-
set tSC = ex.AsStatus()
83+
set tSC = ..DisplayTraceback(ex)
7984
}
8085
quit tSC
8186
}
@@ -111,6 +116,21 @@ Storage Default
111116
<Value name="5">
112117
<Value>%class</Value>
113118
</Value>
119+
<Value name="6">
120+
<Value>%enable</Value>
121+
</Value>
122+
<Value name="7">
123+
<Value>%timeout</Value>
124+
</Value>
125+
<Value name="8">
126+
<Value>%port</Value>
127+
</Value>
128+
<Value name="9">
129+
<Value>%PythonInterpreterPath</Value>
130+
</Value>
131+
<Value name="10">
132+
<Value>%traceback</Value>
133+
</Value>
114134
</Data>
115135
<Data name="persistentProperties">
116136
<Attribute>persistentProperties</Attribute>

src/iop/cls/IOP/BusinessService.cls

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ Parameter SETTINGS = "%classname:Python BusinessService,%module:Python BusinessS
99

1010
Method dispatchProcessInput(pInput As %RegisteredObject) As %RegisteredObject
1111
{
12-
13-
quit ..%class."on_process_input"(pInput)
12+
try {
13+
set response = ..%class."_dispatch_on_process_input"(pInput)
14+
} catch ex {
15+
set tSC = ..DisplayTraceback(ex)
16+
throw ##class(%Exception.StatusException).CreateFromStatus(tSC)
17+
}
18+
quit response
1419
}
1520

1621
Method OnProcessInput(
@@ -27,7 +32,7 @@ Method OnProcessInput(
2732
set ..%WaitForNextCallInterval = ..%class."_wait_for_next_call_interval"
2833
} catch {}
2934
} catch ex {
30-
set tSC = ex.AsStatus()
35+
set tSC = ..DisplayTraceback(ex)
3136
}
3237
quit tSC
3338
}

src/iop/cls/IOP/Common.cls

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Property %port As %Numeric [ InitialExpression = 0 ];
2727

2828
Property %PythonInterpreterPath As %String(MAXLEN = 255);
2929

30+
Property %traceback As %Boolean;
31+
3032
/// Get Class
3133
Method GetClass() As %SYS.Python
3234
{
@@ -45,15 +47,45 @@ Method GetModule() As %String
4547
Return ..%module
4648
}
4749

50+
Method DisplayTraceback(ex) As %Status
51+
{
52+
set tSC = ex.AsStatus()
53+
// Check if traceback is enabled
54+
if ..%traceback {
55+
// Import Modules
56+
set sys = ##class(%SYS.Python).Import("sys")
57+
set tracebackModule = ##class(%SYS.Python).Import("traceback")
58+
set builtins = ##class(%SYS.Python).Import("builtins")
59+
// Get the last traceback
60+
set traceback = sys."last_traceback"
61+
set exType = sys."last_type"."__name__"
62+
set exValue = sys."last_value"."__str__"()
63+
// Check if traceback is an object
64+
if $isObject(traceback) {
65+
// Format the traceback
66+
set tb = tracebackModule."format_exception"(sys."last_type", sys."last_value", traceback)
67+
set tbString = ""
68+
for i=0:1:(tb."__len__"()-1) {
69+
set tbString = tbString _ $c(10)_$c(13) _ tb."__getitem__"(i)
70+
}
71+
$$$LOGERROR(tbString)
72+
set tSC = $$$ERROR($$$EnsErrGeneral,"Exception in Python class: "_..%classname_" - "_exType_" - "_exValue)
73+
}
74+
}
75+
return tSC
76+
}
77+
4878
Method OnInit() As %Status
4979
{
5080
set tSC = $$$OK
5181
try {
82+
do $system.Python.Debugging(..%traceback)
5283
$$$ThrowOnError(..Connect())
5384
do ..%class."_debugpy"($this)
5485
do ..%class."_dispatch_on_init"($this)
5586
} catch ex {
56-
set tSC = ex.AsStatus()
87+
88+
set tSC = ..DisplayTraceback(ex)
5789
}
5890
quit tSC
5991
}
@@ -154,13 +186,14 @@ Method SetPropertyValues()
154186
// First list all the properties of the current class
155187
set class = $CLASSNAME()
156188
set tSQL = "SELECT * FROM %Dictionary.PropertyDefinition WHERE parent = ?"
157-
set tSQL = tSQL _ " AND name <> 'timeout'"
158-
set tSQL = tSQL _ " and name <> 'enable'"
189+
set tSQL = tSQL _ " AND name <> '%timeout'"
190+
set tSQL = tSQL _ " and name <> '%enable'"
159191
set tSQL = tSQL _ " and name <> '%classpaths'"
160192
set tSQL = tSQL _ " and name <> '%classname'"
161193
set tSQL = tSQL _ " and name <> '%module'"
162-
set tSQL = tSQL _ " and name <> 'port'"
163-
set tSQL = tSQL _ " and name <> 'PythonInterpreterPath'"
194+
set tSQL = tSQL _ " and name <> '%port'"
195+
set tSQL = tSQL _ " and name <> '%PythonInterpreterPath'"
196+
set tSQL = tSQL _ " and name <> '%traceback'"
164197

165198
set tStmt = ##class(%SQL.Statement).%New()
166199

src/iop/cls/IOP/InboundAdapter.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Method OnTask() As %Status
1414
$$$ThrowOnError(..Connect())
1515
do ..%class."on_task"()
1616
} catch ex {
17-
set tSC = ex.AsStatus()
17+
set tSC = ..DisplayTraceback(ex)
1818
}
1919
quit tSC
2020
}

src/iop/cls/IOP/OutboundAdapter.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Method OnKeepalive(pStatus As %Status = {$$$OK}) As %Status
2828
$$$ThrowOnError(##super(pStatus))
2929
do ..%class."on_keepalive"()
3030
} catch ex {
31-
set tSC = ex.AsStatus()
31+
set tSC = ..DisplayTraceback(ex)
3232
}
3333
quit tSC
3434
}

src/iop/cls/IOP/Utils.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ ClassMethod GenerateProxyClass(
226226
}
227227

228228
#; Do not display any of the connection settings
229-
#dim tSETTINGSParamValue As %String = "%classname:Python $type,%module:Python $type,%settings:Python $type,%classpaths:Python $type,%enable:Python Debug $type,%timeout:Python Debug $type,%port:Python Debug $type,%PythonInterpreterPath:Python Debug $type"
229+
#dim tSETTINGSParamValue As %String = "%classname:Python $type,%module:Python $type,%settings:Python $type,%classpaths:Python $type,%enable:Python Debug $type,%timeout:Python Debug $type,%port:Python Debug $type,%PythonInterpreterPath:Python Debug $type,%traceback:Python Debug $type"
230230

231231
#dim tPropClassname As %Dictionary.PropertyDefinition = ##class(%Dictionary.PropertyDefinition).%New()
232232
Set tPropClassname.Name = "%classname"

0 commit comments

Comments
 (0)