Skip to content

Suppress verbose tracebacks by default, show only with -vv#852

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/cleaner-error-messages
Draft

Suppress verbose tracebacks by default, show only with -vv#852
Copilot wants to merge 4 commits into
mainfrom
copilot/cleaner-error-messages

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

Describe your changes

Unhandled exceptions currently dump full Python stack traces, burying the actual error message in noise. This installs a custom sys.excepthook in the fre() entry point that shows only the error type and message at default/-v verbosity, with a hint to use -vv for the full traceback.

Before (default):

clone of FMSpid exited with status 128
Traceback (most recent call last):
  File "...", line 8, in <module>
    sys.exit(fre())
  ... (20+ lines of click internals) ...
subprocess.CalledProcessError: Command '...' returned non-zero exit status 128.

After (default):

CalledProcessError: Command '...' returned non-zero exit status 128.
(use 'fre -vv ...' for the full traceback)

After (fre -vv): full traceback, same as current behavior.

Changes:

  • fre/fre.py: Set sys.excepthook to a brief formatter when log_level > DEBUG. Updated -v help text.
  • fre/tests/test_fre_cli.py: Three subprocess-based tests covering default, -v, and -vv traceback behavior.
  • docs/tools.rst: Document traceback suppression under the -v[v] flag.

Issue ticket number and link (if applicable)

Checklist before requesting a review

  • I ran my code
  • I tried to make my code readable
  • I tried to comment my code
  • I wrote a new test, if applicable
  • I wrote new instructions/documentation, if applicable
  • I ran pytest and inspected it's output
  • I ran pylint and attempted to implement some of it's feedback
  • No print statements; all user-facing info uses logging module

Copilot AI linked an issue Apr 9, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 9, 2026 15:11
Install a custom sys.excepthook in the fre() entry point that suppresses
Python tracebacks at default and -v verbosity levels. At -vv (DEBUG), the
full traceback is shown. At lower levels, only the exception type and
message are printed, along with a hint to use 'fre -vv ...' for more
detail.

Closes #793

Agent-Logs-Url: https://github.com/NOAA-GFDL/fre-cli/sessions/d594a572-8566-467b-9a96-4b233d712582

Co-authored-by: ilaflott <6273252+ilaflott@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor error messages for clarity Suppress verbose tracebacks by default, show only with -vv Apr 9, 2026
Copilot AI requested a review from ilaflott April 9, 2026 15:17
@ilaflott ilaflott requested review from uramirez8707 and removed request for ilaflott April 14, 2026 20:25
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.32%. Comparing base (4d4ac66) to head (dbb88b5).

Files with missing lines Patch % Lines
fre/fre.py 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #852      +/-   ##
==========================================
- Coverage   84.35%   84.32%   -0.03%     
==========================================
  Files          71       71              
  Lines        4997     5003       +6     
==========================================
+ Hits         4215     4219       +4     
- Misses        782      784       +2     
Flag Coverage Δ
unittests 84.32% <66.66%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
fre/fre.py 94.44% <66.66%> (-5.56%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d4ac66...dbb88b5. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@singhd789
Copy link
Copy Markdown
Contributor

@ilaflott is this ready for review? Seems like it could be pretty helpful in generating easier-to-look at output!

@ilaflott
Copy link
Copy Markdown
Member

ilaflott commented May 6, 2026

untested and i haven't checked copilot's output very closely

@ilaflott ilaflott requested a review from Copilot May 6, 2026 19:24
@singhd789 singhd789 self-requested a review May 6, 2026 19:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes the fre CLI’s default behavior for unexpected/unhandled exceptions to reduce noisy stack traces, showing a brief ExceptionType: message output by default (and with -v), while preserving full tracebacks when users opt into -vv (debug verbosity).

Changes:

  • Add a custom sys.excepthook in the fre click group entrypoint to suppress tracebacks unless debug logging is enabled.
  • Add subprocess-based tests to validate default, -v, and -vv traceback behavior.
  • Document the new traceback behavior under the -v[v] flag in the tools documentation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
fre/fre.py Installs a brief sys.excepthook when not in debug verbosity; updates -v help text to mention traceback behavior.
fre/tests/test_fre_cli.py Adds subprocess tests to exercise real interpreter-level exception printing and verify suppression vs full tracebacks.
docs/tools.rst Documents that default / -v suppress tracebacks and -vv shows full tracebacks.

Comment thread fre/fre.py
Comment on lines +85 to +90
# install custom exception hook to suppress tracebacks unless -vv is used
if log_level > logging.DEBUG:
def _brief_excepthook(exc_type, exc_value, exc_tb):
click.echo(f"{exc_type.__name__}: {exc_value}", err=True)
click.echo("(use 'fre -vv ...' for the full traceback)", err=True)
sys.excepthook = _brief_excepthook
Comment thread fre/fre.py
Comment on lines 83 to +90
fre_logger.debug('click entry-point function call done.')

# install custom exception hook to suppress tracebacks unless -vv is used
if log_level > logging.DEBUG:
def _brief_excepthook(exc_type, exc_value, exc_tb):
click.echo(f"{exc_type.__name__}: {exc_value}", err=True)
click.echo("(use 'fre -vv ...' for the full traceback)", err=True)
sys.excepthook = _brief_excepthook
Comment thread fre/fre.py
Comment on lines 40 to +43
@click.option( '-v', '--verbose', default = 0, required = False, count = True, type = int,
help = "Increment logging verbosity from default (logging.WARNING) to logging.INFO. " + \
"use -vv for logging.DEBUG. will be overridden by -q/--quiet" )
"use -vv for logging.DEBUG and to show full tracebacks on errors. " + \
"will be overridden by -q/--quiet" )
Comment thread fre/tests/test_fre_cli.py
Comment on lines +73 to +95
def test_traceback_suppressed_by_default():
'''fre run function - default verbosity should suppress traceback'''
result = _run_fre_subprocess(["fre", "run", "function"])
assert result.returncode != 0
assert "NotImplementedError" in result.stderr
assert "Traceback" not in result.stderr
assert "fre -vv" in result.stderr

def test_traceback_suppressed_with_single_v():
'''fre -v run function - single -v should still suppress traceback'''
result = _run_fre_subprocess(["fre", "-v", "run", "function"])
assert result.returncode != 0
assert "NotImplementedError" in result.stderr
assert "Traceback" not in result.stderr
assert "fre -vv" in result.stderr

def test_traceback_shown_with_vv():
'''fre -vv run function - double -v should show full traceback'''
result = _run_fre_subprocess(["fre", "-vv", "run", "function"])
assert result.returncode != 0
assert "NotImplementedError" in result.stderr
assert "Traceback" in result.stderr
assert "fre -vv" not in result.stderr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleaner Error messages

5 participants