Changeset - 2cb131423f97
[Not reviewed]
0 6 0
Brett Smith - 4 years ago 2020-03-28 13:47:40
brettcsmith@brettcsmith.org
errors: Redo InvalidMetadataError.

This needs to be generally usable for transactions.
6 files changed with 13 insertions and 27 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/errors.py
Show inline comments
...
 
@@ -69,16 +69,3 @@ class ConfigurationError(Error):
 
class InvalidMetadataError(Error):
 
    def __init__(self, txn, post, key, value=None, source=None):
 
        if value is None:
 
            msg_fmt = "{post.account} missing {key}"
 
        else:
 
            msg_fmt = "{post.account} has invalid {key}: {value}"
 
        super().__init__(
 
            msg_fmt.format(post=post, key=key, value=value),
 
            txn,
 
            source,
 
        )
 

	
 

	
 
class InvalidEntityError(InvalidMetadataError):
 
    def __init__(self, txn, post=None, key='entity', value=None, source=None):
 
    def __init__(self, txn, key, value=None, post=None, source=None):
 
        if post is None:
...
 
@@ -88,5 +75,5 @@ class InvalidEntityError(InvalidMetadataError):
 
        if value is None:
 
            msg = "{} missing entity".format(srcname)
 
            msg = "{} missing {}".format(srcname, key)
 
        else:
 
            msg = "{} entity malformed: {}".format(srcname, value)
 
        super(InvalidMetadataError, self).__init__(msg, txn, source)
 
            msg = "{} has invalid {}: {}".format(srcname, key, value)
 
        super().__init__(msg, txn, source)
conservancy_beancount/plugin/core.py
Show inline comments
...
 
@@ -219,3 +219,3 @@ class _NormalizePostingMetadataHook(_PostingHook):
 
    def _default_value(self, txn: Transaction, post: data.Posting) -> MetaValueEnum:
 
        raise errormod.InvalidMetadataError(txn, post, self.METADATA_KEY)
 
        raise errormod.InvalidMetadataError(txn, self.METADATA_KEY, None, post)
 

	
...
 
@@ -235,3 +235,3 @@ class _NormalizePostingMetadataHook(_PostingHook):
 
                error = errormod.InvalidMetadataError(
 
                    txn, post, self.METADATA_KEY, source_value,
 
                    txn, self.METADATA_KEY, source_value, post,
 
                )
conservancy_beancount/plugin/meta_entity.py
Show inline comments
...
 
@@ -39,3 +39,3 @@ class MetaEntity(core.TransactionHook):
 
        if txn_entity_ok is False:
 
            yield errormod.InvalidEntityError(txn, value=txn_entity)
 
            yield errormod.InvalidMetadataError(txn, self.METADATA_KEY, txn_entity)
 
        for post in data.iter_postings(txn):
...
 
@@ -45,3 +45,3 @@ class MetaEntity(core.TransactionHook):
 
            if entity is None:
 
                yield errormod.InvalidEntityError(txn, post)
 
                yield errormod.InvalidMetadataError(txn, self.METADATA_KEY, entity, post)
 
            elif entity is txn_entity:
...
 
@@ -49,2 +49,2 @@ class MetaEntity(core.TransactionHook):
 
            elif not self.ENTITY_RE.match(entity):
 
                yield errormod.InvalidEntityError(txn, post, value=entity)
 
                yield errormod.InvalidMetadataError(txn, self.METADATA_KEY, entity, post)
conservancy_beancount/plugin/meta_income_type.py
Show inline comments
...
 
@@ -51,2 +51,2 @@ class MetaIncomeType(core._NormalizePostingMetadataHook):
 
        except KeyError:
 
            raise errormod.InvalidMetadataError(txn, post, self.METADATA_KEY) from None
 
            raise errormod.InvalidMetadataError(txn, self.METADATA_KEY, None, post) from None
conservancy_beancount/plugin/meta_project.py
Show inline comments
...
 
@@ -89,3 +89,2 @@ class MetaProject(core._NormalizePostingMetadataHook):
 
        else:
 
            raise errormod.InvalidMetadataError(txn, post, self.METADATA_KEY)
 

	
 
            raise errormod.InvalidMetadataError(txn, self.METADATA_KEY, None, post)
tests/test_meta_entity.py
Show inline comments
...
 
@@ -62,3 +62,3 @@ def test_invalid_values_on_postings(hook, src_value):
 
    assert len(errors) == 1
 
    assert errors[0].message == "Expenses:General entity malformed: {}".format(src_value)
 
    assert errors[0].message == "Expenses:General has invalid entity: {}".format(src_value)
 

	
...
 
@@ -80,3 +80,3 @@ def test_invalid_values_on_transactions(hook, src_value):
 
    assert 1 <= len(errors) <= 2
 
    assert all(error.message == "transaction entity malformed: {}".format(src_value)
 
    assert all(error.message == "transaction has invalid entity: {}".format(src_value)
 
               for error in hook.run(txn))
0 comments (0 inline, 0 general)