Skip to content

Commit

Permalink
YDA-5912: improve error handling in apply_atomic_operations
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Aug 23, 2024
1 parent e7b11cc commit 8673e05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ def _test_folder_secure_func(ctx, func):
"check": lambda x: (("foo", "bar", "baz") in x
and len([a for a in x if a[0] not in ["org_replication_scheduled"]]) == 1
)},
{"name": "avu.apply_atomic_operations.invalid",
"test": lambda ctx: avu.apply_atomic_operations(ctx, {"inspector": "gadget"}),
"check": lambda x: not x},
{"name": "data_access_token.get_all_tokens",
"test": lambda ctx: data_access_token.get_all_tokens(ctx),
"check": lambda x: isinstance(x, list)},
Expand Down
19 changes: 14 additions & 5 deletions util/avu.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,23 @@ def apply_atomic_operations(ctx, operations):
Operations should be a dict with structure as defined in
https://docs.irods.org/4.2.12/doxygen/libmsi__atomic__apply__metadata__operations_8cpp.html
If an error occurs, all updates are rolled back and an error is returned.
Result will contain specific information about the error.
:param ctx: Combined type of a callback and rei struct
:param operations: Dict containing the batch of metadata operations
:returns: Dict containing the error information on failure
:returns: Boolean indicating if all metadata operations were executed
"""
ret = msi.atomic_apply_metadata_operations(ctx, json.dumps(operations), "")
return json.loads(ret['arguments'][1])
try:
msi.atomic_apply_metadata_operations(ctx, json.dumps(operations), "")
return True
except msi.Error as e:
# iRODS errorcode -1811000 (INVALID_OPERATION)
if str(e).find("-1811000") > -1:
log.write(ctx, "apply_atomic_operations: invalid metadata operation")
# iRODS errorcode -130000 (SYS_INVALID_INPUT_PARAM)
elif str(e).find("-130000") > -1:
log.write(ctx, "apply_atomic_operations: invalid entity name or entity type")
else:
log.write(ctx, "apply_atomic_operations: {}".format(e))
return False

0 comments on commit 8673e05

Please sign in to comment.