mail_deduplicate.bug_report moduleΒΆ
Bug reports for the errors mdedup has no rule for.
Such an error is a bug in mdedup, or a mail shape it does not handle yet. To fix it,
a maintainer needs two facts: the code that raised the error, and the shape of the
mail that triggered it. This module collects both, and hands them to
click_extra.log_report(), which renders them as a block that a user can paste into
an issue, and saves it in the cache directory.
Caution
A report never holds mail content. Mails carry the personal data of their senders
and recipients, and issues are public. So fingerprint() describes a mail by its
structure alone. The traceback keeps module names and line numbers, and drops the
file paths, which hold the name of the user on most systems.
- mail_deduplicate.bug_report.ISSUES_URL = 'https://github.com/kdeldycke/mail-deduplicate/issues'ΒΆ
Where users file bug reports.
Repeats the
IssuesURL ofpyproject.toml, and a test keeps the two in sync: a binary built by Nuitka ships no package metadata to read it from.
- mail_deduplicate.bug_report.REPORT_FORM = 'bug-report.yml'ΒΆ
File name of the issue form a report links to, in
.github/ISSUE_TEMPLATE/.
- mail_deduplicate.bug_report.REPORT_URL = 'https://github.com/kdeldycke/mail-deduplicate/issues/new?template=bug-report.yml'ΒΆ
The
report_urlof themdedupcommand: the bug report form, to whichclick_extra.log_report()adds the title of the issue.
- mail_deduplicate.bug_report.FAILURE_ATTRIBUTE = 'mdedup_failure'ΒΆ
Attribute of an exception that holds the
Failureattached byblame().
- mail_deduplicate.bug_report.FINGERPRINTED_MAILS = 2ΒΆ
Mails of one failure that get a fingerprint.
A failing duplicate set does not tell which of its mails caused the error, and its first two mails usually include the culprit.
- mail_deduplicate.bug_report.MAX_FINGERPRINT_LINES = 60ΒΆ
Cap on the lines of a fingerprint, for mails with hundreds of headers or parts.
- mail_deduplicate.bug_report.MAX_KINDS = 5ΒΆ
Kinds of failure detailed in a report. The warnings of the run name the others.
- mail_deduplicate.bug_report.MAX_VALUE_LENGTH = 200ΒΆ
Cap on the characters of a header value shown verbatim.
- mail_deduplicate.bug_report.PARAMETER_HEADERS = frozenset({'content-disposition', 'content-type'})ΒΆ
Headers a fingerprint shows with their structure only: see
structure().
- mail_deduplicate.bug_report.SAFE_PARAMETERS = frozenset({'charset', 'delsp', 'format', 'micalg', 'protocol', 'report-type', 'type'})ΒΆ
Parameters of
PARAMETER_HEADERSshown as they are: they tell how to read a part.structure()names theSHAPED_PARAMETERSwithout their value, and hides the name of any other parameter too.
- mail_deduplicate.bug_report.SAMPLES = 3ΒΆ
Failures of each kind that a report details, with the fingerprint of their mails.
More samples of the same bug add length to a report, not information, and each fingerprint costs one more read and parse of its mail.
- mail_deduplicate.bug_report.SHAPED_PARAMETERS = frozenset({'boundary', 'filename', 'name'})ΒΆ
Parameters of
PARAMETER_HEADERSa fingerprint names, with their shape alone.They can hold content: a file name, or a boundary built from a sender address.
- mail_deduplicate.bug_report.VERBATIM_HEADERS = frozenset({'content-transfer-encoding', 'date', 'mime-version'})ΒΆ
Headers a fingerprint shows as they are: they hold structure, not content.
Their comments are free text, so
mask_comments()shows each one by its shape.Datecaused several of the past crashes, by its parsing or by the bytes of its comment. See: https://github.com/kdeldycke/mail-deduplicate/issues/600, https://github.com/kdeldycke/mail-deduplicate/issues/954 and https://github.com/kdeldycke/mail-deduplicate/issues/1117
- mail_deduplicate.bug_report.CONTROL_BYTES = re.compile(b'[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]')ΒΆ
C0 control bytes and
DEL, except the tab and the line breaks of a mail.
- mail_deduplicate.bug_report.ENCODED_WORD = re.compile('=\\?([^?\\s]+)\\?([bBqQ])\\?')ΒΆ
Start of an RFC 2047 encoded word: its charset and its encoding.
- mail_deduplicate.bug_report.TOKEN = re.compile("[!#$%&'*+.^_`|~0-9A-Za-z-]+(?:/[!#$%&'*+.^_`|~0-9A-Za-z-]+)?")ΒΆ
An RFC 2045 token, or a
type/subtypepair of them.
- mail_deduplicate.bug_report.plural(count, singular, several=None)[source]ΒΆ
Count things in words, or say nothing about a count of zero.
- Return type:
- mail_deduplicate.bug_report.to_bytes(text)[source]ΒΆ
Recover the bytes a parsed value came from.
Parsing a mail from bytes keeps each non-ASCII byte as a lone surrogate, which
surrogateescapeturns back into that byte. Other surrogates come from no byte, sosurrogatepasswrites them as the invalid UTF-8 they are.- Return type:
- mail_deduplicate.bug_report.byte_class(value)[source]ΒΆ
Describe a value by its length and the kind of its bytes, never by its bytes.
- Return type:
- mail_deduplicate.bug_report.shape(value)[source]ΒΆ
Describe a value by its bytes, its folding and its encoded words.
- Return type:
- mail_deduplicate.bug_report.verbatim(value)[source]ΒΆ
Show a value as it is, with its folding collapsed and its length capped.
A value holding non-ASCII bytes renders as
bytes, so each byte shows as an escape rather than as a lone surrogate.- Return type:
- mail_deduplicate.bug_report.mask_comments(value)[source]ΒΆ
Replace the text of each comment of a header value by its shape.
A comment is free text in parentheses, which RFC 5322 allows between the tokens of a structured header. Some mail clients write the name of their time zone there, after a
Date, and some their own name, afterMIME-Version. A comment can hold others, and a backslash quotes the character after it. A comment left open runs to the end of the value.- Return type:
- mail_deduplicate.bug_report.split_parameters(value)[source]ΒΆ
Split a header value on its semicolons, except the ones in a quoted string.
- mail_deduplicate.bug_report.structure(value)[source]ΒΆ
Show a
Content-TypeorContent-Dispositionvalue by its structure alone.The leading
type/subtypeor disposition shows as it is, and so do theSAFE_PARAMETERS. TheSHAPED_PARAMETERSkeep their name, and any other parameter shows as?, all of them with the shape of their value only.- Return type:
- mail_deduplicate.bug_report.header_value(name, value)[source]ΒΆ
Show a header value as its name allows: verbatim, by structure, or by shape.
A verbatim value still shows its comments by their shape.
- Return type:
- mail_deduplicate.bug_report.line_endings(raw)[source]ΒΆ
Name the line endings of a mail, with their counts when they are mixed.
- Return type:
- mail_deduplicate.bug_report.first_raw(part, name)[source]ΒΆ
The raw value of the first header of a part with that name.
A parsed header holding 8-bit bytes reads back as a
Headerobject, and its raw value as a string with lone surrogates, whichto_bytes()turns back to bytes.
- mail_deduplicate.bug_report.part_lines(part, depth=0)[source]ΒΆ
One line per MIME part, with the subparts of a multipart indented under it.
- mail_deduplicate.bug_report.fingerprint(raw)[source]ΒΆ
Describe a mail by its structure, with none of its content.
The description shows the size and line endings of the mail, then every header name, in order. Headers in
VERBATIM_HEADERSshow their value but for their comments, those inPARAMETER_HEADERStheir structure, and any other one only the shape of its value: length, kind of bytes, folding and encoded words. Then comes the MIME tree, with the type, charset, transfer encoding and kind of bytes of each part, the preamble and epilogue of each multipart, and the defects the parser found.Never raises: a mail too broken to describe gets a line saying so.
- Return type:
- mail_deduplicate.bug_report.fingerprint_mail(mail)[source]ΒΆ
The
fingerprint()of a mail, read again from its source.Never raises: a mail that cannot be read again gets a line saying so.
- Return type:
- mail_deduplicate.bug_report.box_format_of(item)[source]ΒΆ
The format of a box, or of the box a mail comes from.
- Return type:
- class mail_deduplicate.bug_report.Failure(step, error, frames, function='', culprits=(), formats=(), fingerprints=(), trace='')[source]ΒΆ
Bases:
objectAn error mdedup has no rule for, reduced to strings.
Strings can leave a worker process, and keep nothing alive: the mails, boxes and frames of the error are dropped as soon as it is captured.
- function: str = ''ΒΆ
The innermost function of mdedup the error went through, as
click_extra.culprit_function()finds it.
- culprits: tuple[str, ...] = ()ΒΆ
The
repr()of each mail involved. They hold paths, so they never reach the report block.
- fingerprints: tuple[str, ...] = ()ΒΆ
The fingerprint of the first mails involved, or nothing for a failure that is not a sample.
- trace: str = ''ΒΆ
The full traceback, for the debug log, or nothing for a failure that is not a sample.
- property kind: tuple[str, str, str]ΒΆ
Failures of one kind share their step, exception class and raising line.
- property title: strΒΆ
The title of an issue reporting the failure.
It names the exception class, the innermost function of mdedup in the traceback and the step. Reports of the same bug get the same title, so GitHub lists the issue already open for it while the next user types theirs. The function tells apart two bugs raising the same class in the same step, and unlike a line number, it does not change between releases.
- mail_deduplicate.bug_report.capture(expt, step, mails=(), sample=True)[source]ΒΆ
Reduce an error to a
Failure.Only a sample gets the fingerprints of its first mails and the full traceback: both cost far more than the rest.
- Return type:
- mail_deduplicate.bug_report.failure_lines(samples, title)[source]ΒΆ
The lines of a report detailing one kind of failure.
- class mail_deduplicate.bug_report.FailureLog[source]ΒΆ
Bases:
objectThe failures of a run: each one counted, the first
SAMPLESof a kind kept.Memory stays flat however many mails fail the same way, which a single bug can make all of them do.
- samples: dict[tuple[str, str, str], list[Failure]]ΒΆ
The first failures of each kind, in the order they happened.
- capture(expt, step, mails=())[source]ΒΆ
Reduce an error to a
Failure, sampled while its kind has room left.- Return type:
- add(failure)[source]ΒΆ
Count a failure, and keep it if its kind still has room for a sample.
- Return type:
- headline()[source]ΒΆ
The first line of the report, saying how much the failures set aside.
It also says that the run continued, as the word
errorreads to some users as a crash that stopped everything.- Return type:
- mail_deduplicate.bug_report.log_report(level, headline, title, details, sources)[source]ΒΆ
Log a bug report with
click_extra.log_report(), the sources listed first.The format of each source tells which code of
mailboxread it, which the options of the run do not say.- Return type:
- mail_deduplicate.bug_report.blame(mail, step)[source]ΒΆ
Attach the mail being processed to any error escaping the block.
The error goes on to stop the run, and
report_unexpected_errors()names the mail. It also fingerprints the mail in the bug report, except for anOSError, which gets no bug report.
- mail_deduplicate.bug_report.report_unexpected_errors(dedup)[source]ΒΆ
End the run with a one-line error or a bug report, whatever escapes the block.
The exceptions of Click pass through: they are how a command exits, or refuses an input. An
OSErrorcomes from the system, like a missing permission or a full disk, so the user can fix it: it ends the run with a one-line error. Any other error is a bug. Its traceback is logged with the report inviting the user to file it, and the run exits with code 1.