Skip to content

str(pysam.SamtoolsError("...")) always gives a escaped string #1344

@Fan-iX

Description

@Fan-iX

pysam.SamtoolsError uses a repr() in its __str__ method,

pysam/pysam/utils.py

Lines 13 to 21 in 55b9c0b

class SamtoolsError(Exception):
'''exception raised in case of an error incurred in the samtools
library.'''
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)

so I always get an escaped error message in the log file when I except pysam.SamtoolsError as e: logfile.write(str(e))

'samtools returned with error 1: stdout=, stderr=samtools index: failed to create index for "some_broken.bam"\n'

I don't think it's necessary to escape error messages, which makes SamtoolsError behave differently than common python Exceptions.

>>> str(pysam.SamtoolsError("error"))
"'error'"
>>> str(Exception("error"))
'error'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions