diff --git a/src/borg/hashindex.pyx b/src/borg/hashindex.pyx index 97fc213f10..607d3456e8 100644 --- a/src/borg/hashindex.pyx +++ b/src/borg/hashindex.pyx @@ -78,7 +78,8 @@ class ChunkIndex(HTProxyMixin, MutableMapping): flags = self.F_USED else: flags = v.flags | self.F_USED - assert v.size == 0 or v.size == size + if v.size != 0 and v.size != size: + raise ValueError(f"Invalid size: expected 0 or {size}, got {v.size}") self[key] = ChunkIndexEntry(flags=flags, size=size) def __getitem__(self, key): @@ -217,8 +218,10 @@ class NSIndex1(HTProxyMixin, MutableMapping): magic, entries, buckets, ksize, vsize = struct.unpack(self.HEADER_FMT, header_bytes) if magic != self.MAGIC: raise ValueError(f"Invalid file, magic {self.MAGIC.decode()} not found.") - assert ksize == self.KEY_SIZE, "invalid key size" - assert vsize == self.VALUE_SIZE, "invalid value size" + if ksize != self.KEY_SIZE: + raise ValueError("Invalid key size") + if vsize != self.VALUE_SIZE: + raise ValueError("Invalid value size") buckets_size = buckets * (ksize + vsize) current_pos = fd.tell() end_of_file = fd.seek(0, os.SEEK_END) @@ -230,4 +233,5 @@ class NSIndex1(HTProxyMixin, MutableMapping): value = fd.read(vsize) self.ht._set_raw(key, value) pos = fd.tell() - assert pos == end_of_file + if pos != end_of_file: + raise ValueError(f"Expected pos ({pos}) to be at end_of_file ({end_of_file})") diff --git a/src/borg/platform/posix.pyx b/src/borg/platform/posix.pyx index 84c413701e..0b2e71c018 100644 --- a/src/borg/platform/posix.pyx +++ b/src/borg/platform/posix.pyx @@ -44,10 +44,14 @@ def process_alive(host, pid, thread): from . import local_pid_alive from . import hostid - assert isinstance(host, str) - assert isinstance(hostid, str) - assert isinstance(pid, int) - assert isinstance(thread, int) + if not isinstance(host, str): + raise TypeError("host must be a string") + if not isinstance(hostid, str): + raise TypeError("hostid must be a string") + if not isinstance(pid, int): + raise TypeError("pid must be an integer") + if not isinstance(thread, int): + raise TypeError("thread must be an integer") if host != hostid: return True @@ -116,7 +120,8 @@ def group2gid(group, default=None): def posix_acl_use_stored_uid_gid(acl): """Replace the user/group field with the stored uid/gid """ - assert isinstance(acl, bytes) + if not isinstance(acl, bytes): + raise TypeError("acl must be of type bytes") from ..helpers import safe_decode, safe_encode entries = [] for entry in safe_decode(acl).split('\n'):