pmb: Handle BuildFailedError (MR 2288)

Also breaks out hinting printing code into its own function to avoid
repetition.

Closes https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2068
This commit is contained in:
Newbyte 2024-04-03 09:43:24 +02:00 committed by Oliver Smith
parent d5badd1b0e
commit 2972f1d36e
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 18 additions and 9 deletions

View File

@ -5,8 +5,9 @@ import sys
import logging
import os
import traceback
from argparse import Namespace
from pmb.helpers.exceptions import NonBugError
from pmb.helpers.exceptions import BuildFailedError, NonBugError
from . import config
from . import parse
@ -28,6 +29,16 @@ if version < (3, 9):
sys.exit()
def print_log_hint(args: Namespace) -> None:
# Hints about the log file (print to stdout only)
log_hint = "Run 'pmbootstrap log' for details."
if not args or not os.path.exists(args.log):
log_hint += (" Alternatively you can use '--details-to-stdout' to get more"
" output, e.g. 'pmbootstrap --details-to-stdout init'.")
print()
print(log_hint)
def main():
# Wrap everything to display nice error messages
args = None
@ -80,6 +91,11 @@ def main():
logging.error(exception)
return 2
except BuildFailedError as exception:
logging.error(exception)
print_log_hint(args)
return 3
except Exception as e:
# Dump log to stdout when args (and therefore logging) init failed
if not args:
@ -89,14 +105,7 @@ def main():
logging.info("See also: <https://postmarketos.org/troubleshooting>")
logging.debug(traceback.format_exc())
# Hints about the log file (print to stdout only)
log_hint = "Run 'pmbootstrap log' for details."
if not args or not os.path.exists(args.log):
log_hint += (" Alternatively you can use '--details-to-stdout' to"
" get more output, e.g. 'pmbootstrap"
" --details-to-stdout init'.")
print()
print(log_hint)
print_log_hint(args)
print()
print("Before you report this error, ensure that pmbootstrap is "
"up to date.")