Skip to content

Conversation

@dhimmel
Copy link
Contributor

@dhimmel dhimmel commented Aug 29, 2019

No description provided.

pdoc/cli.py Outdated
for opt in args.config:
try:
config_key, config_value = opt.split('=', 1)
config_value = ast.literal_eval(config_value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

literal_eval is more restricted than eval and thus prevents certain vulnerabilities. Not sure if anyone is using features supported only by eval?

raise RuntimeError(
'Error evaluating config value {!r}\n'
'Make sure string values are quoted?'.format(opt, e)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switches error message to being for the single bad config option to hopefully be more specific.

pdoc/cli.py Outdated
except Exception as e:
raise RuntimeError(
'Error evaluating config value {!r}\n'
'Make sure string values are quoted?'.format(opt, e)
Copy link
Member

Choose a reason for hiding this comment

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

Template is missing a placeholder for e.

If opt is repr-ed, don't we end up with too many quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If opt is repr-ed, don't we end up with too many quotes?

Possibly, it could be useful for the unquoted configuration value case, but probably better without overall.

>>> print("{!r}".format("'configuration_value'"))
"'configuration_value'"
>>> print("{!r}".format("'configuration value'"))
"'configuration value'"
>>> print("{!r}".format('"configuration value"'))
'"configuration value"'
>>> print("{!r}".format("unquoted configuration value"))
'unquoted configuration value'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Template is missing a placeholder for e.

Addressed in 78d3152

@dhimmel
Copy link
Contributor Author

dhimmel commented Aug 30, 2019

As of 78d3152, here is the output for a bad --config:

pdoc3 --html \
  --template-dir doc/pdoc_template \
  --force --output-dir doc \
  --config "variable=this should be bad" \
  pdoc

Traceback (most recent call last):
  File "/home/dhimmel/Documents/repos/pdoc/pdoc/cli.py", line 378, in main
    config_value = ast.literal_eval(config_value)
  File "/home/dhimmel/anaconda3/lib/python3.6/ast.py", line 48, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/home/dhimmel/anaconda3/lib/python3.6/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    this should be bad
              ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dhimmel/Documents/repos/pdoc/bin/pdoc3", line 11, in <module>
    load_entry_point('pdoc3', 'console_scripts', 'pdoc3')()
  File "/home/dhimmel/Documents/repos/pdoc/pdoc/cli.py", line 384, in main
    .format(error.__class__.__name__, config_str, error)
RuntimeError: SyntaxError evaluating --config variable=this should be bad
invalid syntax (<unknown>, line 1)
Make sure string values are quoted?

A bit repetitive and verbose, but it gets the problem across. Another option is to raise a warning rather than an error and proceed with execution.

@kernc
Copy link
Member

kernc commented Sep 1, 2019

Too severe for a warning. Made it just a tad less repetitive, as you say. Thanks!

@kernc kernc merged commit 44c9606 into pdoc3:master Sep 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants