Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VRE Language
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KIT
virtmat-tools
VRE Language
Commits
0e1f9c23
Commit
0e1f9c23
authored
1 month ago
by
Adersh Joshy_Philip
Browse files
Options
Downloads
Patches
Plain Diff
Updated error.py
parent
f1f98fd3
No related branches found
No related tags found
1 merge request
!338
Resolve "Jupyter notebook issues"
Pipeline
#417431
failed
1 month ago
Stage: Static Analysis
Stage: Regression Tests
Stage: Build Docs
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/virtmat/language/utilities/errors.py
+65
-99
65 additions, 99 deletions
src/virtmat/language/utilities/errors.py
with
65 additions
and
99 deletions
src/virtmat/language/utilities/errors.py
+
65
−
99
View file @
0e1f9c23
#NEW CODE
"""
handling domain-specific errors
"""
import
sys
import
importlib
...
...
@@ -7,6 +9,15 @@ from pint.errors import OffsetUnitCalculusError
from
ase.calculators.calculator
import
CalculatorSetupError
from
virtmat.middleware.exceptions
import
ResourceConfigurationError
from
virtmat.language.utilities.textx
import
get_location_context
from
.exceptions
import
(
ObjectImportError
,
ObjectFromFileError
,
ObjectSchemaValidationError
,
ObjectAlreadyExistsError
,
ObjectNotFoundError
,
ObjectConversionError
,
ObjectUniqueConstraintError
)
FILE_READ_EXCEPTION_IMPORTS
=
{
'
ruamel.yaml.parser
'
:
'
ParserError
'
,
'
ruamel.yaml.scanner
'
:
'
ScannerError
'
,
...
...
@@ -226,77 +237,59 @@ def format_textxerr_msg(err):
return
msg
@textxerror_wrap
def
raise_exception
(
_
,
exception
,
msg
,
where_used
=
None
):
"""
utility function to raise an exception at a custom location
"""
if
where_used
is
not
None
:
err
=
TextXError
(
''
,
**
get_location_context
(
where_used
))
msg
+=
f
'
\n
used here:
{
format_textxerr_msg
(
err
)
}
'
raise
exception
(
msg
)
try
:
from
ruamel.yaml.error
import
MarkedYAMLError
except
(
ModuleNotFoundError
,
AttributeError
):
class
MarkedYAMLError
(
Exception
):
pass
try
:
from
jsonschema
import
ValidationError
except
(
ModuleNotFoundError
,
AttributeError
):
class
ValidationError
(
Exception
):
pass
try
:
from
pymongo.errors
import
DuplicateKeyError
except
(
ModuleNotFoundError
,
AttributeError
):
class
DuplicateKeyError
(
Exception
):
pass
TEXTX_WRAPPED_EXCEPTIONS
=
(
DimensionalityError
,
UndefinedUnitError
,
PintError
,
InvalidUnitError
,
CalculatorSetupError
,
StructureInputError
,
StaticTypeError
,
RuntimeTypeError
,
StaticValueError
,
RuntimeValueError
,
PropertyError
,
SubscriptingError
,
EvaluationError
,
AncestorEvaluationError
,
ArithmeticError
,
FileExistsError
,
OSError
)
try
:
from
bson.errors
import
BSONError
except
(
ModuleNotFoundError
,
AttributeError
):
class
BSONError
(
Exception
):
pass
def
process_error
(
err
):
"""
generic error processor for errors of class TextXError
"""
if
err
.
err_type
is
None
:
if
isinstance
(
err
,
TextXSyntaxError
):
err_type
=
'
Syntax error
'
elif
isinstance
(
err
,
TextXSemanticError
):
err_type
=
'
Semantic error
'
elif
isinstance
(
err
.
__cause__
,
DimensionalityError
):
err_type
=
'
Dimensionality error
'
elif
isinstance
(
err
.
__cause__
,
UndefinedUnitError
):
err_type
=
'
Undefined unit
'
elif
isinstance
(
err
.
__cause__
,
OffsetUnitCalculusError
):
err_type
=
'
Offset unit calculus error
'
elif
isinstance
(
err
.
__cause__
,
PintError
):
err_type
=
'
Units error
'
elif
isinstance
(
err
.
__cause__
,
InvalidUnitError
):
err_type
=
'
Invalid units error
'
elif
isinstance
(
err
.
__cause__
,
CalculatorSetupError
):
err_type
=
'
Calculator setup error
'
elif
isinstance
(
err
.
__cause__
,
StructureInputError
):
err_type
=
'
Structure input error
'
elif
isinstance
(
err
.
__cause__
,
(
StaticTypeError
,
RuntimeTypeError
)):
err_type
=
'
Type error
'
elif
isinstance
(
err
.
__cause__
,
(
StaticValueError
,
RuntimeValueError
)):
err_type
=
'
Value error
'
elif
isinstance
(
err
.
__cause__
,
PropertyError
):
err_type
=
'
Invalid key
'
elif
isinstance
(
err
.
__cause__
,
SubscriptingError
):
err_type
=
'
Invalid index
'
elif
isinstance
(
err
.
__cause__
,
ConvergenceError
):
err_type
=
'
Convergence error
'
elif
isinstance
(
err
.
__cause__
,
EvaluationError
):
err_type
=
'
Evaluation error
'
elif
isinstance
(
err
.
__cause__
,
AncestorEvaluationError
):
err_type
=
'
Ancestor evaluation error
'
elif
isinstance
(
err
.
__cause__
,
UpdateError
):
err_type
=
'
Variable update error
'
elif
isinstance
(
err
.
__cause__
,
TagError
):
err_type
=
'
Tag error
'
elif
isinstance
(
err
.
__cause__
,
ResourceConfigurationError
):
err_type
=
'
Resource configuration error
'
elif
isinstance
(
err
.
__cause__
,
ArithmeticError
):
err_type
=
'
Arithmetic error
'
elif
isinstance
(
err
.
__cause__
,
NotImplementedError
):
err_type
=
'
Not implemented
'
elif
isinstance
(
err
.
__cause__
,
FileExistsError
):
err_type
=
'
File exists error
'
elif
isinstance
(
err
.
__cause__
,
OSError
):
err_type
=
'
Operating system error
'
err_type
=
"
Error
"
if
err
.
__cause__
is
not
None
:
if
isinstance
(
err
.
__cause__
,
MarkedYAMLError
):
err_type
=
'
YAML syntax error
'
elif
isinstance
(
err
.
__cause__
,
ValidationError
):
err_type
=
'
Schema validation error
'
elif
isinstance
(
err
.
__cause__
,
DuplicateKeyError
):
err_type
=
'
Duplicate key error
'
elif
isinstance
(
err
.
__cause__
,
BSONError
):
err_type
=
'
BSON encoding/decoding error
'
elif
isinstance
(
err
.
__cause__
,
ObjectImportError
):
err_type
=
'
Object import error
'
elif
isinstance
(
err
.
__cause__
,
ObjectFromFileError
):
err_type
=
'
Object from file error
'
elif
isinstance
(
err
.
__cause__
,
ObjectSchemaValidationError
):
err_type
=
'
Object schema validation error
'
elif
isinstance
(
err
.
__cause__
,
ObjectAlreadyExistsError
):
err_type
=
'
Object already exists error
'
elif
isinstance
(
err
.
__cause__
,
ObjectNotFoundError
):
err_type
=
'
Object not found error
'
elif
isinstance
(
err
.
__cause__
,
ObjectConversionError
):
err_type
=
'
Object conversion error
'
elif
isinstance
(
err
.
__cause__
,
ObjectUniqueConstraintError
):
err_type
=
'
Object unique constraint error
'
else
:
raise
err
.
__cause__
else
:
err_type
=
err
.
err_type
print_stderr
(
err_type
+
'
:
'
+
format_textxerr_msg
(
err
))
return
err_type
def
error_handler
(
func
):
...
...
@@ -304,39 +297,12 @@ def error_handler(func):
def
wrapper
(
*
args
,
**
kwargs
):
try
:
return
func
(
*
args
,
**
kwargs
)
except
TextXError
as
err
:
process_error
(
err
)
return
None
except
ObjectFromFileError
as
err
:
cause_cls
=
err
.
__cause__
.
__class__
.
__qualname__
cause_mod
=
err
.
__cause__
.
__class__
.
__module__
print_stderr
(
f
'
{
cause_mod
}
.
{
cause_cls
}
:
{
err
.
path
}
:
{
err
.
__cause__
}
'
)
return
None
except
CompatibilityError
as
err
:
print_stderr
(
f
'
Compatibility error:
{
err
}
'
)
return
None
except
VaryError
as
err
:
print_stderr
(
f
'
Vary error:
{
err
}
'
)
return
None
except
QueryError
as
err
:
print_stderr
(
f
'
Query error:
{
err
}
'
)
return
None
except
ReuseError
as
err
:
print_stderr
(
f
'
Reuse error:
{
err
}
'
)
return
None
except
ModelNotFoundError
as
err
:
print_stderr
(
f
'
Model not found:
{
err
}
'
)
return
None
except
ConfigurationError
as
err
:
print_stderr
(
f
'
Configuration error:
{
err
}
'
)
return
None
except
UpdateError
as
err
:
print_stderr
(
f
'
Variable update error:
{
err
}
'
)
return
None
except
tuple
([
*
MONGODB_EXCEPTIONS
,
*
FILE_READ_EXCEPTIONS
])
as
err
:
err_cls
=
err
.
__class__
print_stderr
(
f
'
{
err_cls
.
__module__
}
.
{
err_cls
.
__qualname__
}
:
{
err
}
'
)
return
None
except
Exception
as
err
:
raise
RuntimeError
(
'
non-handled exception
'
)
from
err
return
wrapper
err_type
=
process_error
(
err
)
print_stderr
(
format_textxerr_msg
(
f
'
{
err_type
}
:
{
err
}
'
))
if
isinstance
(
err
,
ObjectFromFileError
):
cause_cls
=
err
.
__cause__
.
__class__
.
__qualname__
cause_mod
=
err
.
__cause__
.
__class__
.
__module__
print_stderr
(
f
'
{
cause_mod
}
.
{
cause_cls
}
:
{
err
.
path
}
:
{
err
.
__cause__
}
'
)
raise
RuntimeError
(
'
Unhandled exception occurred
'
)
from
err
return
wrapper
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment