Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling #296

Merged
merged 25 commits into from
Nov 19, 2020
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5c65b69
Transform parse functions into object_set methods
achaikou Aug 5, 2020
2e03f62
Add missing physical layout tests
achaikou Sep 22, 2020
66cb3ee
Fail truncated files in findoffsets
achaikou Nov 18, 2020
2b129df
Introduce dlis_error and error_severity
achaikou Oct 15, 2020
6a556bd
Add error_handler
achaikou Nov 5, 2020
4da7baa
Propagate attribute warnings to Python
achaikou Nov 5, 2020
f9927ce
Sometimes allow invalid representation codes
achaikou Nov 5, 2020
7da826a
Immediately store procesed data in object set
achaikou Oct 15, 2020
1c34cdd
Inform objects about problems in attributes
achaikou Nov 5, 2020
3d96334
Move check for broken descriptors to higer level
achaikou Nov 6, 2020
c29f604
Propagate object set warnings to Python
achaikou Nov 6, 2020
0bdc3ca
Propagate object warnings to Python
achaikou Nov 6, 2020
223c543
Inform users about redundant and replacement sets
achaikou Sep 17, 2020
98726e5
Add error handler tests
achaikou Oct 28, 2020
23b88a0
Allow users to read trucated and zeroed files
achaikou Nov 18, 2020
8ccb9d0
Add error handler to extract method
achaikou Sep 21, 2020
c4ba9c2
Add error handler to findfdata method
achaikou Sep 22, 2020
97c316e
Divide read_fdata function
achaikou Sep 23, 2020
dd927f6
Add error handler to readfdata
achaikou Oct 15, 2020
2de34f1
Add error handler to parse
achaikou Nov 18, 2020
99d0127
Add error handler to parse_objects
achaikou Nov 6, 2020
db83c95
Fix object not found error message
achaikou Nov 6, 2020
b816b30
Handle "count is larger" issue in parse
achaikou Sep 23, 2020
9ca5902
Inform user when padbytes number equals LRS length
achaikou Oct 15, 2020
4630e53
Add combined error handler tests
achaikou Nov 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add error handler tests
We detect various specification violation. Some of them we consider
insignificant enough and recover.
Out users can, however, disagree with us about importance of certain
specification violations.
Hence we give users a little bit more control over it.

For example, users want to receive an error every time something is
spoiled even a little bit.
Or on the opposite - users may want to get as much data as possible,
accepting the danger that data might be spoiled.
  • Loading branch information
achaikou committed Nov 19, 2020
commit 98726e520c7bb422ea3d4ccd74f49b973063e4bd
77 changes: 77 additions & 0 deletions python/tests/test_error_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
Testing error handler on various levels of representation
(user-facade functionality and underlying logical format)
"""

import pytest
import os

import dlisio

from dlisio.errors import ErrorHandler, Actions

errorhandler = ErrorHandler(critical = Actions.LOG_ERROR)

# TODO: test_errors_explicit (let users examine the errors regardless of escape
# level set)

# TODO: test mix (do not fail on truncation, but fail on bad attribute access)

# TODO: test_truncated

# TODO: test_extract

# TODO: test_parse_exeptions

def test_parse_critical_escaped(tmpdir, merge_files_oneLR,
assert_error):
path = os.path.join(str(tmpdir), 'error-on-attribute-access.dlis')
content = [
'data/chap3/start.dlis.part',
'data/chap3/template/invalid-repcode-no-value.dlis.part',
'data/chap3/object/object.dlis.part',
'data/chap3/objattr/empty.dlis.part',
]
merge_files_oneLR(path, content)

with dlisio.load(path, error_handler=errorhandler) as (f, *_):
obj = f.object('VERY_MUCH_TESTY_SET', 'OBJECT', 1, 1)
# value is unclear and shouldn't be trusted
_ = obj['INVALID']
assert_error("invalid representation code")

def test_parse_major_errored(tmpdir, merge_files_oneLR):
path = os.path.join(str(tmpdir), 'replacement-set.dlis')
content = [
'data/chap3/sul.dlis.part',
'data/chap3/set/replacement.dlis.part',
'data/chap3/template/default.dlis.part',
'data/chap3/object/object.dlis.part'
]
merge_files_oneLR(path, content)

errorhandler = ErrorHandler(
major=Actions.RAISE)
with dlisio.load(path, error_handler=errorhandler) as (f, *_):
with pytest.raises(RuntimeError) as excinfo:
_ = f.object('REPLACEMENT', 'OBJECT', 1, 1)
assert "Replacement sets are not supported" in str(excinfo.value)

def test_parse_minor_errored(tmpdir, merge_files_oneLR):
path = os.path.join(str(tmpdir), 'redundant-set.dlis')
content = [
'data/chap3/sul.dlis.part',
'data/chap3/set/redundant.dlis.part',
'data/chap3/template/default.dlis.part',
'data/chap3/object/object.dlis.part'
]
merge_files_oneLR(path, content)

errorhandler = ErrorHandler(
major=Actions.RAISE,
minor=Actions.RAISE
)
with dlisio.load(path, error_handler=errorhandler) as (f, *_):
with pytest.raises(RuntimeError) as excinfo:
_ = f.object('REDUNDANT', 'OBJECT', 1, 1)
assert "Redundant sets are not supported" in str(excinfo.value)