Skip to content

Conversation

@pietvr
Copy link

@pietvr pietvr commented Oct 11, 2019

Give rst line and file information upon exceptions in sphinx_selective_exclude

Example syntax error:

.. someItem

.. only:: whenSomethingEnabled
       someItemSometime

With this fix the exception info:

/home/dev/mysphynx/index.rst:15: WARNING: exception while evaluating 'only' directive expression: chunk after expression  

Fixes #6

if not env.app.builder.tags.eval_condition(self.arguments[0]):
return []
except Exception as err:
logger = logging.getLogger(__name__)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be a global variable of the file, or a class-member, or property or whatever. Having it here in the except only, will force new logs to copy this line around...

Copy link
Owner

Choose a reason for hiding this comment

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

this should be a global variable

+1. And please initialize it as logger = sphinx.util.logging.getLogger(__name__) to avoid confusion of what it is.

Copy link
Author

Choose a reason for hiding this comment

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

I have done this now.

Sorry I missed this comment.

Comment on lines 39 to 40
logger.warning(('exception while evaluating only directive expression: %s'), err,
location=(self.env.docname, self.lineno))
Copy link
Contributor

Choose a reason for hiding this comment

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

are we sure we just want to log a warning and continue building? There probably wont be any html/latex generated for this directive due to this syntax error. And not every rst-write cares too much about terminal warnings. Two suggestions:

  • or 1, we still fail the sphinx-build but give more details on where the syntax error is located
  • or 2, we add some warning in the generated html/latex as well stating there was a syntax error,

for option 1, we could derive a specific Exception class where we added more details. For an example see https://github.com/melexis/sphinx-traceability-extension/blob/master/mlx/traceability_exception.py#L38-L60

Copy link
Author

Choose a reason for hiding this comment

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

Stein,

I intended to raise. So I corrected this already.

For this exception class. I do not know whether there is much added value at this point.
This sphinx_selective_exclude is only 1 file so it is still clean like it is added now.

Usually I add this class the second time I add the same code.

Piet

Copy link
Owner

Choose a reason for hiding this comment

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

"exception while evaluating ... expression" looks like an logger.error() to me, not logger.warning(). Extra confirmed by the fact that you raise after it (so it's treated as kinda-fatal, which is not ideal, but ok).

@pietvr
Copy link
Author

pietvr commented Oct 24, 2019

Hello @pfalcon,

Can you merge this one?
It improves to syntax error handling of the sphinx_selective_exclude.

Regards,
Piet,

return []
except Exception as err:
logger = logging.getLogger(__name__)
logger.warning(('exception while evaluating only directive expression: %s'), err,
Copy link
Owner

Choose a reason for hiding this comment

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

This should be "exception while evaluating 'only' directive expression", otherwise it's confusing. Parens around message are superfluous.

Copy link
Author

Choose a reason for hiding this comment

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

I've done this

@pfalcon
Copy link
Owner

pfalcon commented Oct 24, 2019

Sorry, I'm too busy with the real life currently, and preparing for travel, so won't be able to look into this in detail (at least) until 2nd half of November.

In the meantime, a few suggestion based on a quick look. Please squash any fixes into the original commit. Also, if you didn't yet do that, please do "git log" and follow the same format for the commit message.

Also, can you please add an example of erroneous syntax and corresponding error message generated with this patch?

Thanks!

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.

Exceptions do not show rst line and file.

4 participants