mirror of https://github.com/eyhc1/rendercv.git
add exception handling for UnicodeDecodeError in handle_exceptions function
This commit is contained in:
parent
c1470650ac
commit
066a6a4e9b
|
@ -303,6 +303,19 @@ def handle_exceptions(function: Callable) -> Callable:
|
||||||
error("There is a YAML error in the input file!", e)
|
error("There is a YAML error in the input file!", e)
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
error(e)
|
error(e)
|
||||||
|
except UnicodeDecodeError as e:
|
||||||
|
# find the problematic character that cannot be decoded with utf-8
|
||||||
|
bad_character = str(e.object[e.start : e.end])
|
||||||
|
try:
|
||||||
|
bad_character_context = str(e.object[e.start - 16 : e.end + 16])
|
||||||
|
except IndexError:
|
||||||
|
bad_character_context = ""
|
||||||
|
|
||||||
|
error(
|
||||||
|
"The input file contains a character that cannot be decoded with"
|
||||||
|
f" UTF-8 ({bad_character}):\n {bad_character_context}",
|
||||||
|
)
|
||||||
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
error(e)
|
error(e)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
|
@ -405,11 +418,14 @@ def cli_command_render(
|
||||||
str,
|
str,
|
||||||
typer.Argument(help="Path to the YAML input file as a string"),
|
typer.Argument(help="Path to the YAML input file as a string"),
|
||||||
],
|
],
|
||||||
use_local_latex: bool = typer.Option(
|
use_local_latex: Annotated[
|
||||||
False,
|
bool,
|
||||||
"--use-local-latex",
|
typer.Option(
|
||||||
help="Use the local LaTeX installation instead of the RenderCV's TinyTeX.",
|
False,
|
||||||
),
|
"--use-local-latex",
|
||||||
|
help="Use the local LaTeX installation instead of the RenderCV's TinyTeX.",
|
||||||
|
),
|
||||||
|
] = False,
|
||||||
):
|
):
|
||||||
"""Generate a $\\LaTeX$ CV from a YAML input file.
|
"""Generate a $\\LaTeX$ CV from a YAML input file.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue