From d809ff01a61c0988bc231fbcf4e70e1485c49d25 Mon Sep 17 00:00:00 2001 From: Simon Chopin Date: Tue, 13 Feb 2024 20:10:04 +0100 Subject: [PATCH 1/2] retrace: move the duplicate checks into helper function --- bin/apport-retrace | 47 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/bin/apport-retrace b/bin/apport-retrace index e0a0fc4b0..eba1f7dab 100755 --- a/bin/apport-retrace +++ b/bin/apport-retrace @@ -394,6 +394,29 @@ Thank you for your understanding, and sorry for the inconvenience! ) +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) + 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 + ) + return False + apport.logging.log("Duplicate check negative", options.timestamps) + return True + + # pylint: disable-next=missing-function-docstring def main(argv): # TODO: Split into smaller functions/methods @@ -629,29 +652,7 @@ Thank you for your understanding, and sorry for the inconvenience! " 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 needs_update(report, options, crashid, crashdb): if "Stacktrace" in report: crashdb.update_traces(crashid, report) apport.logging.log( From 5f5bbfbe97765aaa61d56487d10f653e10a4ea6f Mon Sep 17 00:00:00 2001 From: Simon Chopin Date: Tue, 13 Feb 2024 20:10:04 +0100 Subject: [PATCH 2/2] retrace: move the bug updates into helper function --- bin/apport-retrace | 91 ++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/bin/apport-retrace b/bin/apport-retrace index eba1f7dab..f6d60bac8 100755 --- a/bin/apport-retrace +++ b/bin/apport-retrace @@ -417,6 +417,53 @@ def needs_update( return True +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( + 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) + + 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) + + # pylint: disable-next=missing-function-docstring def main(argv): # TODO: Split into smaller functions/methods @@ -653,49 +700,7 @@ Thank you for your understanding, and sorry for the inconvenience! ) if not options.confirm or confirm_traces(report): if needs_update(report, options, crashid, crashdb): - 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) - + update_bug(report, options, outdated_msg, crashid, crashdb) elif options.output == "-": report.write(sys.stdout.detach()) else: