Skip to content

Commit

Permalink
catching markdown errors and passing in special extras kwarg to disab…
Browse files Browse the repository at this point in the history
…le markup if it sees an error

how is this not the default behavior? maybe consider submitting a pr 🤔
  • Loading branch information
jessebot committed Apr 27, 2024
1 parent 0e03044 commit f6e7c63
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions smol_k8s_lab/utils/subproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from subprocess import Popen, PIPE
import re
from rich.console import Console
from rich.markup import MarkupError
from rich.theme import Theme
from rich.progress import Progress
from time import sleep
Expand Down Expand Up @@ -133,7 +134,13 @@ def run_subprocess(command: str, decode_ascii: bool = False, **kwargs):

# if quiet = True, or res_stdout is empty, we hide this
if res_stdout and not quiet:
log.info(res_stdout)
try:
log.info(res_stdout)
except MarkupError:
log.debug(
"Rich logging errored because there's special characters in the"
" output and rich can't render the markdown.")
log.info(res_stdout, extra={"markup": False})

if res_stderr and not quiet:
log.info(res_stderr)
Expand All @@ -156,7 +163,7 @@ def run_subprocess(command: str, decode_ascii: bool = False, **kwargs):
return output


def simple_loading_bar(tasks: dict, time_to_wait: int = 120):
def simple_loading_bar(tasks: dict, time_to_wait: int = 120) -> None:
"""
Prints a small loading bar using rich.
Accepts a dict of {"task_name": "task"}
Expand Down

0 comments on commit f6e7c63

Please sign in to comment.