Skip to content

Commit

Permalink
fix: print out error if exception is raised in python executable; els…
Browse files Browse the repository at this point in the history
…e raise entire stacktrace
  • Loading branch information
n-dusan committed Sep 23, 2024
1 parent dc08dba commit 2c85ff1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion taf/tools/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import click

from functools import partial, wraps
from logging import ERROR
from logdecorator import log_on_error

from taf.exceptions import TAFError
from taf.log import taf_logger

from taf.utils import is_run_from_python_executable

def catch_cli_exception(func=None, *, handle, print_error=False):
if not func:
Expand All @@ -18,6 +19,11 @@ def wrapper(*args, **kwargs):
except handle as e:
if print_error:
click.echo(e)
except Exception as e:
if is_run_from_python_executable():
click.echo(f"An error occurred: {e}")
else:
raise e

return wrapper

Expand Down
8 changes: 8 additions & 0 deletions taf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tempfile
import shutil
import uuid
import sys
from getpass import getpass
from functools import wraps
from pathlib import Path
Expand Down Expand Up @@ -135,6 +136,13 @@ def is_non_empty_directory(path: Path):
return False


def is_run_from_python_executable() -> bool:
"""
`sys frozen returns True if the Python interpreter is frozen using a tool like pyinstaller.
"""
return getattr(sys, 'frozen', False)


def read_input_dict(value):
if value is None:
return {}
Expand Down

0 comments on commit 2c85ff1

Please sign in to comment.