Skip to content

Commit

Permalink
Improve user messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpvorderman committed Nov 4, 2024
1 parent 8a35f9e commit 497310f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/dnaio/_bam.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ def read_bam_header(fileobj: BufferedIOBase) -> bytes:
magic = fileobj.read(4)
if not isinstance(magic, bytes):
raise TypeError(
f"fileobj {fileobj} is not a binary IO type, " f"got {type(fileobj)}"
f"fileobj {fileobj} (type: {type(fileobj)}), was not opened in binary mode."
)
if len(magic) < 4:
raise EOFError("Truncated BAM file")
if magic[:4] != b"BAM\1":
raise ValueError(
f"fileobj: {fileobj}, is not a BAM file. No BAM magic, instead "
f"fileobj: {fileobj}, is not a BAM file. No BAM file signature, instead "
f"found {magic!r}"
)
return read_bam_header_after_magic(fileobj)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def test_bam_parser_not_binary_error(self):
)
with pytest.raises(TypeError) as error:
BamReader(file)
error.match("binary IO")
error.match("binary mode")

@pytest.mark.parametrize("buffersize", [4, 8, 10, 20, 40])
def test_small_buffersize(self, buffersize):
Expand Down

0 comments on commit 497310f

Please sign in to comment.