Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't break on IndexError in logging #9068

Merged
merged 3 commits into from
Mar 19, 2025
Merged

Conversation

tstadel
Copy link
Member

@tstadel tstadel commented Mar 19, 2025

Related Issues

  • fixes haystack logging raising another error when logging exceptions

We've seen this for a production pipeline:

IndexError: Replacement index 0 out of range for positional args tuple

Here's the logline that caused this error:

except Exception as e:
            logger.error(
                f"Component {component.__class__.__name__} with prefix '{prefix}' failed with exception: {str(e)}",
                exc_info=True,
            )

relevant stacktrace:

  File "/home/haystackd/.local/lib/python3.12/site-packages/haystack/logging.py", line 144, in _log_only_with_kwargs
    return func(
           ^^^^^
  File "/home/haystackd/.pyenv/versions/3.12.8/lib/python3.12/logging/__init__.py", line 1568, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/home/haystackd/.pyenv/versions/3.12.8/lib/python3.12/logging/__init__.py", line 1682, in _log
    record = self.makeRecord(self.name, level, fn, lno, msg, args,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/haystackd/.local/lib/python3.12/site-packages/haystack/logging.py", line 194, in _wrapper
    interpolated_msg = msg.format(**safe_extra)
                       ^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: Replacement index 0 out of range for positional args tuple

Proposed Changes:

  • catch IndexError

How did you test it?

Notes for the reviewer

  • a general catch all would be even safer I guess

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I documented my code
  • I ran pre-commit hooks and fixed any issue

@tstadel tstadel requested a review from a team as a code owner March 19, 2025 11:45
@tstadel tstadel requested review from julian-risch and removed request for a team March 19, 2025 11:45
@tstadel tstadel requested a review from a team as a code owner March 19, 2025 11:49
@tstadel tstadel requested review from dfokina and removed request for a team March 19, 2025 11:49
@coveralls
Copy link
Collaborator

coveralls commented Mar 19, 2025

Pull Request Test Coverage Report for Build 13946181933

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 90.068%

Totals Coverage Status
Change from base Build 13945256266: 0.0%
Covered Lines: 9740
Relevant Lines: 10814

💛 - Coveralls

Copy link
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@davidsbatista davidsbatista merged commit 9a046ed into main Mar 19, 2025
17 checks passed
@davidsbatista davidsbatista deleted the fix/logging_indexerror branch March 19, 2025 16:46
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.

4 participants