Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
SBML.jl
Commits
024e76fc
Unverified
Commit
024e76fc
authored
Jul 15, 2021
by
Miroslav Kratochvil
🚴
Committed by
GitHub
Jul 15, 2021
Browse files
Merge pull request #117 from LCSB-BioCore/mk-error-severities
handle SBML error severities (and don't throw on warnings)
parents
d3413c43
54b60a1c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/readsbml.jl
View file @
024e76fc
...
...
@@ -72,7 +72,11 @@ function get_optional_double(x::VPtr, is_sym, get_sym)::Maybe{Float64}
end
"""
function readSBML(fn::String, sbml_conversion = model->nothing)::SBML.Model
readSBML(
fn::String,
sbml_conversion = document -> nothing;
report_severities = ["
Fatal
", "
Error
"],
)::SBML.Model
Read the SBML from a XML file in `fn` and return the contained `SBML.Model`.
...
...
@@ -82,6 +86,9 @@ single parameter, which is the C pointer to the loaded SBML document (C type
[`set_level_and_version`](@ref), [`libsbml_convert`](@ref), and
[`convert_simplify_math`](@ref).
`report_severities` switches on and off reporting of certain errors; see the
documentation of [`get_error_messages`](@ref) for details.
# Example
```
m = readSBML("
my_model
.
xml
", doc -> begin
...
...
@@ -90,10 +97,18 @@ m = readSBML("my_model.xml", doc -> begin
end)
```
"""
function
readSBML
(
fn
::
String
,
sbml_conversion
=
document
->
nothing
)
::
SBML
.
Model
function
readSBML
(
fn
::
String
,
sbml_conversion
=
document
->
nothing
;
report_severities
=
[
"Fatal"
,
"Error"
],
)
::
SBML
.
Model
doc
=
ccall
(
sbml
(
:
readSBML
),
VPtr
,
(
Cstring
,),
fn
)
try
get_error_messages
(
doc
,
AssertionError
(
"Opening SBML document has reported errors"
))
get_error_messages
(
doc
,
AssertionError
(
"Opening SBML document has reported errors"
),
report_severities
,
)
sbml_conversion
(
doc
)
...
...
src/utils.jl
View file @
024e76fc
...
...
@@ -148,26 +148,45 @@ function extensive_kinetic_math(
end
"""
get_error_messages(doc::Ptr
{Cvoid}
, error::Exception)
get_error_messages(doc::
V
Ptr, error::Exception
, report_severities
)
Show the error messages reported by SBML in the `doc` document and throw the
`error` if they are more than 1.
`report_severities` switches the reporting of certain error types defined by
libsbml; you can choose from `["
Fatal
", "
Error
", "
Warning
", "
Informational
"]`.
"""
function
get_error_messages
(
doc
::
VPtr
,
error
::
Exception
)
function
get_error_messages
(
doc
::
VPtr
,
error
::
Exception
,
report_severities
)
n_errs
=
ccall
(
sbml
(
:
SBMLDocument_getNumErrors
),
Cuint
,
(
VPtr
,),
doc
)
do_throw
=
false
for
i
=
1
:
n_errs
err
=
ccall
(
sbml
(
:
SBMLDocument_getError
),
VPtr
,
(
VPtr
,
Cuint
),
doc
,
i
-
1
)
msg
=
string
(
strip
(
get_string
(
err
,
:
XMLError_getMessage
)))
@error
"SBML reported error:
$(msg)
"
end
if
n_errs
>
0
throw
(
error
)
sev
=
string
(
strip
(
get_string
(
err
,
:
XMLError_getSeverityAsString
)))
# keywords from `libsbml/src/sbml/xml/XMLError.cpp` xmlSeverityStringTable:
if
sev
==
"Fatal"
sev
in
report_severities
&&
@error
"SBML reported fatal error:
$(msg)
"
do_throw
=
true
elseif
sev
==
"Error"
sev
in
report_severities
&&
@error
"SBML reported error:
$(msg)
"
do_throw
=
true
elseif
sev
==
"Warning"
sev
in
report_severities
&&
@warn
"SBML reported warning:
$(msg)
"
elseif
sev
==
"Informational"
sev
in
report_severities
&&
@info
"SBML reported:
$(msg)
"
end
end
do_throw
&&
throw
(
error
)
nothing
end
"""
check_errors(success::Integer, doc::Ptr{Cvoid}, error::Exception)
check_errors(
success::Integer,
doc::VPtr,
error::Exception,
report_severities = ["
Fatal
", "
Error
"],
)
If success is a 0-valued `Integer` (a logical `false`), then call
[`get_error_messages`](@ref) to show the error messages reported by SBML in the
...
...
@@ -175,5 +194,9 @@ If success is a 0-valued `Integer` (a logical `false`), then call
typically the value returned by an SBML C function operating on `doc` which
returns a boolean flag to signal a successful operation.
"""
check_errors
(
success
::
Integer
,
doc
::
VPtr
,
error
::
Exception
)
=
Bool
(
success
)
||
get_error_messages
(
doc
,
error
)
check_errors
(
success
::
Integer
,
doc
::
VPtr
,
error
::
Exception
,
report_severities
=
[
"Fatal"
,
"Error"
],
)
=
Bool
(
success
)
||
get_error_messages
(
doc
,
error
,
report_severities
)
cylon-x
🤖
@cylon-x
mentioned in commit
63f1fc59
·
Jul 15, 2021
mentioned in commit
63f1fc59
mentioned in commit 63f1fc591f915a714c4a73b86909bdabfc644d84
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment