Skip to content

fix(logging): add context to bare and generic error log messages#848

Open
balgaly wants to merge 2 commits into
pyupio:mainfrom
balgaly:fix/improve-error-messages-577
Open

fix(logging): add context to bare and generic error log messages#848
balgaly wants to merge 2 commits into
pyupio:mainfrom
balgaly:fix/improve-error-messages-577

Conversation

@balgaly

@balgaly balgaly commented Apr 8, 2026

Copy link
Copy Markdown

Summary

Addresses #577 by improving three error log calls that were either bare (no message) or generic (no context about what failed).

Changes

safety/scan/util.py

__run__ logged LOG.exception(e) with no message when a git command failed. The log now includes the command string so it is clear which git invocation caused the error:

# before
LOG.exception(e)

# after
LOG.exception("Failed to run git command %r: %s", " ".join(self.git + cmd), e)

safety/auth/server.py

The authentication completion handler logged a bare LOG.exception(e). Added a descriptive prefix so the log entry is self-explanatory:

# before
LOG.exception(e)

# after
LOG.exception("Authentication server error: %s", e)

safety/safety.py (remediation version parsing)

Three LOG.error calls said only "Error getting X version, ignoring" with no indication of which package or what version string caused the failure. The messages now include the unparseable version string and the package spec:

# before
LOG.error("Error getting upper remediation version, ignoring", exc_info=True)

# after
LOG.error(
    "Error parsing upper remediation version %r for %s, ignoring",
    spec.remediation.closest_secure.upper,
    spec,
    exc_info=True,
)

These are pure logging changes with no impact on runtime behaviour.

Three log calls emitted no context or had generic messages that made
debugging harder:

- scan/util.py: include the failing git command in the exception log
- auth/server.py: add descriptive prefix to bare LOG.exception(e) call
- safety.py: include the unparseable version string and package spec
  in remediation version error messages

Part of pyupio#577
@coderabbitai

coderabbitai Bot commented Apr 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ff5e619f-4960-4151-946c-b5225fbd063d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@balgaly

balgaly commented Apr 11, 2026

Copy link
Copy Markdown
Author

Friendly ping. happy to make any changes needed to get this across the line. The fix adds context to two categories of error log messages that were previously bare or too generic to be actionable in production. Let me know if there are style or scope concerns. 🙏

@safety-bot

Copy link
Copy Markdown
Contributor

🚀 Artifacts — PR #848 by @balgaly (source: balgaly/safety)

Security notice: You are viewing pre-release CI artifacts from PR #848 by @balgaly (source: balgaly/safety). These commands may execute code on your machine. Do NOT run them unless you have reviewed the PR diff and trust the source. The snippets include a confirmation prompt.

Download the wheel file and binaries with gh CLI or from the workflow artifacts.

📦 Install & Run

Pre-requisites

# Install uv if needed
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create and enter artifacts directory
mkdir artifacts && cd artifacts

Quick Test with Python Package

bash -c 'set -euo pipefail; echo; echo "WARNING: You are about to download and execute CI artifacts from PR #848 by @balgaly (source: balgaly/safety). Do NOT proceed unless you have reviewed the PR diff and trust the source."; echo; read -rp "Type I understand to continue: " C; [ "$C" = "I understand" ] || { echo "Aborted."; exit 1; }; gh run download 24139254342 -n dist -R pyupio/safety; uvx safety-*-py3-none-any.whl --version'

Run other Safety commands as follows

uvx safety-*-py3-none-any.whl auth status
uvx safety-*-py3-none-any.whl auth login
uvx safety-*-py3-none-any.whl scan

Note: You need to be logged in to GitHub to access the artifacts.

self.git contains a Path element so str.join on self.git + cmd
fails pyright's type check. Cast each element to str explicitly.
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.

2 participants