Skip to content

Commit 9de6fb5

Browse files
committed
Callout try catch wrappers
1 parent 796d792 commit 9de6fb5

File tree

2 files changed

+56
-17
lines changed

2 files changed

+56
-17
lines changed

isc/py/Callout.cls

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Main callout wrapper.
1+
/// Raw callout wrapper. Use isc.py.Main
22
/// To use:
33
/// 1. Call: do ##class(isc.py.Callout).Setup() once per systems start
44
/// 2. Call main method (can be called many times, context persists): write ##class(isc.py.Callout).SimpleString(code, data)
@@ -44,10 +44,29 @@ $g(^isc.py.Callout, $g(^%SYS("bindir")) _ "iscpython." _ $select($$$isWINDOWS:"d
4444
/// Should be executed once per system start. Idempotent.
4545
/// Add to ZSTART or production start.
4646
/// write ##class(isc.py.Callout).Setup()
47-
ClassMethod Setup()
47+
ClassMethod Setup() As %Status
4848
{
49-
set sc = $ZF(-4,6,..#PyLibId)
50-
set sc = $ZF(-4,5,..#PyLibId, ..GetLib())
49+
#dim sc As %Status = $$$OK
50+
set file = ..GetLib()
51+
quit:'##class(%File).Exists(file) $$$ERROR($$$GeneralError, "Library file: " _ file _ " does not exist")
52+
53+
try {
54+
set result = $ZF(-4,6,..#PyLibId)
55+
if result'=0 {
56+
set sc = $$$ERROR($$$GeneralError, "Failed $ZF(-4, 6,..#PyLibId) call with result: " _ result _ " expected 0")
57+
quit
58+
}
59+
60+
set result =$ZF(-4,5,..#PyLibId, file)
61+
if result'=0 {
62+
set sc = $$$ERROR($$$GeneralError, "Failed $ZF(-4, 5,..GetLib()) call with result: " _ result _ " expected 0")
63+
quit
64+
}
65+
} catch ex {
66+
set sc = ex.AsStatus()
67+
}
68+
69+
5170
quit sc
5271
}
5372

@@ -61,12 +80,18 @@ ClassMethod Setup()
6180
/// In cause of problems: do ##class(isc.py.Callout).Initialize("libpython3.6m.so")
6281
ClassMethod Initialize(file As %String = "", debug As %Boolean = {$$$NO}) As %Integer
6382
{
64-
if debug {
65-
set sc = $ZF(-4,4,..#PyLibId) // unload current copy of inputlib
66-
set sc = $ZF(-4,8) // delete existing process index, if any
67-
set sc = $ZF(-4,7,..#PyLibId, ..GetLib()) // override system index
83+
#dim sc As %Status = $$$OK
84+
try {
85+
if debug {
86+
set sc = $ZF(-4,4,..#PyLibId) // unload current copy of inputlib
87+
set sc = $ZF(-4,8) // delete existing process index, if any
88+
set sc = $ZF(-4,7,..#PyLibId, ..GetLib()) // override system index
89+
}
90+
do $ZF(-6, ..#PyLibId, ..#Initialize, file)
91+
} catch ex {
92+
set sc = ex.AsStatus()
6893
}
69-
do $ZF(-6, ..#PyLibId, ..#Initialize, file)
94+
quit sc
7095
}
7196

7297
/// Test method. Get random number
@@ -169,18 +194,32 @@ ClassMethod StreamExecute() As %Status
169194
}
170195

171196
/// Finalize Python. Idempotent.
172-
/// do ##class(isc.py.Callout).Finalize()
173-
ClassMethod Finalize() As %Integer
197+
/// write ##class(isc.py.Callout).Finalize()
198+
ClassMethod Finalize() As %Status
174199
{
175-
do $ZF(-6, ..#PyLibId, ..#Finalize)
200+
try {
201+
do $ZF(-6, ..#PyLibId, ..#Finalize)
202+
} catch ex {
203+
#dim ex As %Exception.General
204+
set sc = ex.AsStatus()
205+
}
206+
quit sc
176207
}
177208

178209
/// Unload library. Idempotent.
179210
/// write ##class(isc.py.Callout).Unload()
180-
ClassMethod Unload() As %Integer
211+
ClassMethod Unload() As %Status
181212
{
182-
set result = $ZF(-4, 4, ..#PyLibId)
183-
quit result
213+
#dim sc As %Status = $$$OK
214+
215+
try {
216+
set result = $ZF(-4, 4, ..#PyLibId)
217+
set:result'=0 sc = $$$ERROR($$$GeneralError, "Failed $ZF(-4, 4,..#PyLibId) call with result: " _ result _ " expected 0")
218+
} catch ex {
219+
set sc = ex.AsStatus()
220+
}
221+
222+
quit sc
184223
}
185224

186225
}

isc/py/Main.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Class isc.py.Main
33
{
44

55
/// This method assumes that variable value is less than $$$MaxStringLength limit
6-
/// Eval code vaiable in initialized context and
7-
/// optionally return value of variable str evaluation
6+
/// Eval code in initialized context and
7+
/// optionally return variable value.
88
/// serialization - currenlty: 0 - string serialization, 1 - repr serialization.
99
/// write ##class(isc.py.Main).SimpleString()
1010
ClassMethod SimpleString(code As %String = "", variable As %String = "", serialization As %Integer = 0, Output result) As %Status

0 commit comments

Comments
 (0)