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 TypeError when exc_info=False #42

Merged
merged 7 commits into from
Jul 6, 2021

Conversation

stj
Copy link
Contributor

@stj stj commented Mar 18, 2021

Formatting of a message fails in the StdlibFormatter when the
exc_info parameter is False. The traceback shows that handling of
the boolean is not done correct in the formatting for error type and
message.

Traceback (most recent call last):
  File "lib/python3.8/logging/__init__.py", line 1081, in emit
    msg = self.format(record)
  File "lib/python3.8/logging/__init__.py", line 925, in format
    return fmt.format(record)
  File "ecs_logging/_stdlib.py", line 117, in format
    result = self.format_to_ecs(record)
  File "ecs_logging/_stdlib.py", line 163, in format_to_ecs
    value = extractors[field](record)
  File "ecs_logging/_stdlib.py", line 150, in <lambda>
    if (r.exc_info is not None and r.exc_info[0] is not None)
TypeError: 'bool' object is not subscriptable

This replaces the lambda with methods handling exc_info being an
boolean or iterable.

Formatting of a message fails in the `StdlibFormatter` when the
`exc_info` parameter is `False`. The traceback shows that handling of
the boolean is not done correct in the formatting for error type and
message.

```python
Traceback (most recent call last):
  File "lib/python3.8/logging/__init__.py", line 1081, in emit
    msg = self.format(record)
  File "lib/python3.8/logging/__init__.py", line 925, in format
    return fmt.format(record)
  File "ecs_logging/_stdlib.py", line 117, in format
    result = self.format_to_ecs(record)
  File "ecs_logging/_stdlib.py", line 163, in format_to_ecs
    value = extractors[field](record)
  File "ecs_logging/_stdlib.py", line 150, in <lambda>
    if (r.exc_info is not None and r.exc_info[0] is not None)
TypeError: 'bool' object is not subscriptable
```

This replaces the lambda with methods handling `exc_info` being an
boolean or iterable.
@stj stj requested a review from sethmlarson March 18, 2021 04:59
@stj stj self-assigned this Mar 18, 2021
@apmmachine
Copy link
Contributor

apmmachine commented Mar 18, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-07-06T16:36:02.320+0000

  • Duration: 8 min 24 sec

  • Commit: 19c9834

Test stats 🧪

Test Results
Failed 0
Passed 243
Skipped 11
Total 254

Trends 🧪

Image of Build Times

Image of Tests

Copy link
Contributor

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

Thanks for this. Here's some comments for you, going to tag in other reviewers.

ecs_logging/_stdlib.py Show resolved Hide resolved
ecs_logging/_stdlib.py Outdated Show resolved Hide resolved
ecs_logging/_stdlib.py Outdated Show resolved Hide resolved
@stj stj requested a review from sethmlarson April 4, 2021 05:02
@sethmlarson
Copy link
Contributor

jenkins test this please

@sethmlarson
Copy link
Contributor

jenkins test this please

@basepi basepi dismissed sethmlarson’s stale review July 6, 2021 16:30

Changes incorporated.

@basepi basepi merged commit c95313e into elastic:master Jul 6, 2021
@basepi basepi assigned basepi and unassigned stj Jul 6, 2021
@stj stj deleted the fix-error-when-exc_info-is-false branch August 20, 2021 23:15
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