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

logging.warning cannot handle passing an Exception #834

Open
fafrd opened this issue Jul 5, 2023 · 1 comment
Open

logging.warning cannot handle passing an Exception #834

fafrd opened this issue Jul 5, 2023 · 1 comment

Comments

@fafrd
Copy link

fafrd commented Jul 5, 2023

logging.error, .warning etc functions let you pass in basically anything. For example, I can pass in an Exception here:

try:
  raise ValueError('test')
except Exception as e:
  logging.warning(e)
WARNING:root:test

The serverless SDK can't handle this:

    try:
        raise ValueError("test")
    except Exception as e:
        logging.warning(e)
"message": "unsupported operand type(s) for %: 'ValueError' and 'tuple'",

"stack": "Traceback (most recent call last):
  File \"/var/task/handle_generate_certificate.py\", line 28, in handle_generate_certificate
    raise ValueError(\"test\")
ValueError: test

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/opt/python/sls_sdk/lib/instrumentation/logging.py\", line 56, in __warning
    _resolve_message(*args), origin=\"pythonLogging\"
  File \"/opt/python/sls_sdk/lib/instrumentation/logging.py\", line 22, in _resolve_message
    return args[0] % args[1:]
TypeError: unsupported operand type(s) for %: 'ValueError' and 'tuple'
",

It works for logging.error but not for logging.warning. You should probably add a similar isinstance(args[0], BaseException) check to the _warning function here: https://github.com/serverless/console/blob/main/python/packages/sdk/sls_sdk/lib/instrumentation/logging.py#L45

@fafrd
Copy link
Author

fafrd commented Jul 5, 2023

Workaround is to stringify first: logging.warning(str(e))

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

No branches or pull requests

1 participant