Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 72 additions & 66 deletions bin/apport-retrace
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,76 @@
)


def needs_update(
report: Report, options: Namespace, crashid: int, crashdb: CrashDatabase
) -> bool:
"""Checks whether we need to update a given bug report."""
# check for duplicates
if options.duplicate_db:
crashdb.init_duplicate_db(options.duplicate_db)
res = crashdb.check_duplicate(crashid, report)

Check warning on line 404 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L403-L404

Added lines #L403 - L404 were not covered by tests
if res:
if res[1] is None:
version = "not fixed yet"

Check warning on line 407 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L407

Added line #L407 was not covered by tests
elif res[1] == "":
version = "fixed in latest version"

Check warning on line 409 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L409

Added line #L409 was not covered by tests
else:
version = f"fixed in version {res[1]}"
apport.logging.log(

Check warning on line 412 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L411-L412

Added lines #L411 - L412 were not covered by tests
f"Report is a duplicate of #{res[0]} ({version})", options.timestamps
)
return False
apport.logging.log("Duplicate check negative", options.timestamps)
return True

Check warning on line 417 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L415-L417

Added lines #L415 - L417 were not covered by tests


def update_bug(
report: Report,
options: Namespace,
outdated_msg: str | None,
crashid: int,
crashdb: CrashDatabase,
) -> None:
"""Update the bug in the crash db with the retracing data."""
if "Stacktrace" in report:
crashdb.update_traces(crashid, report)
apport.logging.log(

Check warning on line 430 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L429-L430

Added lines #L429 - L430 were not covered by tests
f"New attachments uploaded to crash database LP: #{crashid}",
options.timestamps,
)
else:
# this happens when gdb crashes
apport.logging.log("No stack trace, invalid report", options.timestamps)

Check warning on line 436 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L436

Added line #L436 was not covered by tests

if not report.has_useful_stacktrace():
if outdated_msg:
invalid_msg = f"""Thank you for your report!

Check warning on line 440 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L440

Added line #L440 was not covered by tests

However, processing it in order to get sufficient information for the
developers failed (it does not generate a useful symbolic stack trace). This
might be caused by some outdated packages which were installed on your system
at the time of the report:

{outdated_msg}

Please upgrade your system to the latest package versions. If you still
encounter the crash, please file a new report.

Thank you for your understanding, and sorry for the inconvenience!
"""
apport.logging.log(

Check warning on line 454 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L454

Added line #L454 was not covered by tests
"No crash signature and outdated packages, invalidating report",
options.timestamps,
)
crashdb.mark_retrace_failed(crashid, invalid_msg)

Check warning on line 458 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L458

Added line #L458 was not covered by tests
else:
apport.logging.log(

Check warning on line 460 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L460

Added line #L460 was not covered by tests
"Report has no crash signature, so retrace is flawed",
options.timestamps,
)
crashdb.mark_retrace_failed(crashid)

Check warning on line 464 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L464

Added line #L464 was not covered by tests


# pylint: disable-next=missing-function-docstring
def main(argv):
# TODO: Split into smaller functions/methods
Expand Down Expand Up @@ -629,72 +699,8 @@
" back to the crash database."
)
if not options.confirm or confirm_traces(report):
# check for duplicates
update_bug = True
if options.duplicate_db:
crashdb.init_duplicate_db(options.duplicate_db)
res = crashdb.check_duplicate(crashid, report)
if res:
if res[1] is None:
version = "not fixed yet"
elif res[1] == "":
version = "fixed in latest version"
else:
version = f"fixed in version {res[1]}"
apport.logging.log(
f"Report is a duplicate of #{res[0]} ({version})",
options.timestamps,
)
update_bug = False
else:
apport.logging.log(
"Duplicate check negative", options.timestamps
)

if update_bug:
if "Stacktrace" in report:
crashdb.update_traces(crashid, report)
apport.logging.log(
f"New attachments uploaded to crash database"
f" LP: #{crashid}",
options.timestamps,
)
else:
# this happens when gdb crashes
apport.logging.log(
"No stack trace, invalid report", options.timestamps
)

if not report.has_useful_stacktrace():
if outdated_msg:
invalid_msg = f"""Thank you for your report!

However, processing it in order to get sufficient information for the
developers failed (it does not generate a useful symbolic stack trace). This
might be caused by some outdated packages which were installed on your system
at the time of the report:

{outdated_msg}

Please upgrade your system to the latest package versions. If you still
encounter the crash, please file a new report.

Thank you for your understanding, and sorry for the inconvenience!
"""
apport.logging.log(
"No crash signature and outdated packages,"
" invalidating report",
options.timestamps,
)
crashdb.mark_retrace_failed(crashid, invalid_msg)
else:
apport.logging.log(
"Report has no crash signature,"
" so retrace is flawed",
options.timestamps,
)
crashdb.mark_retrace_failed(crashid)

if needs_update(report, options, crashid, crashdb):
update_bug(report, options, outdated_msg, crashid, crashdb)

Check warning on line 703 in bin/apport-retrace

View check run for this annotation

Codecov / codecov/patch

bin/apport-retrace#L703

Added line #L703 was not covered by tests
elif options.output == "-":
report.write(sys.stdout.detach())
else:
Expand Down