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

If error msg contains a curly bracket, log will fail when attempting to use format #188

Open
marcoquerque opened this issue Mar 31, 2020 · 3 comments

Comments

@marcoquerque
Copy link

marcoquerque commented Mar 31, 2020

I have a syntax error in a file that is involves an error message with a curly bracket:

The msg here:

log('{0}{1}ERROR{2}: {3}'.format(BRIGHT, RED, RESET, msg), *args, **kwargs)

I imagine contains the curly bracket which causes an issue at the format call here:

m = msg if kwargs.get('noformat', False) else msg.format(*args)

@marcoquerque marcoquerque changed the title If error msg contains a curly bracket, log will fail when attempted to use format If error msg contains a curly bracket, log will fail when attempting to use format Mar 31, 2020
@rubik
Copy link
Owner

rubik commented Apr 1, 2020

Interesting. Can you provide a minimal code sample that shows the error?

@marcoquerque
Copy link
Author

This is a very simple use case, I imagine there could be others:

def not_python_3():
    print "}"

python3 raises a syntax error:
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("}")?

Radon can't capture the error because while doing so it has its own error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/radon/__init__.py", line 15, in main
    program()
  File "/usr/local/lib/python3.7/site-packages/mando/core.py", line 201, in __call__
    return self.execute(sys.argv[1:])
  File "/usr/local/lib/python3.7/site-packages/mando/core.py", line 197, in execute
    return command(*a)
  File "/usr/local/lib/python3.7/site-packages/radon/cli/__init__.py", line 119, in cc
    stream=stream)
  File "/usr/local/lib/python3.7/site-packages/radon/cli/__init__.py", line 321, in log_result
    log_error(h_args[0], indent=1)
  File "/usr/local/lib/python3.7/site-packages/radon/cli/__init__.py", line 353, in log_error
    log('{0}{1}ERROR{2}: {3}'.format(BRIGHT, RED, RESET, msg), *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/radon/cli/__init__.py", line 338, in log
    m = msg if kwargs.get('noformat', False) else msg.format(*args)
ValueError: Single '}' encountered in format string

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/radon", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/radon/__init__.py", line 17, in main
    log_error(e)
  File "/usr/local/lib/python3.7/site-packages/radon/cli/__init__.py", line 353, in log_error
    log('{0}{1}ERROR{2}: {3}'.format(BRIGHT, RED, RESET, msg), *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/radon/cli/__init__.py", line 338, in log
    m = msg if kwargs.get('noformat', False) else msg.format(*args)
ValueError: Single '}' encountered in format string```

@marcoquerque
Copy link
Author

Generalizing this issue, any error that happens during parsing, that throws an error with a curly bracket in its message, radon is likely to fail instead of capturing that error.

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

2 participants