Skip to content

Improve error/warning handling in Config #536

@waylan

Description

@waylan

While working on moving the markdown extension handling to the config, I noticed a few oddities with how errors and warnings are handled within the config. And taking a closer look at the code I see even more. I could just do a PR, but wanted some feedback on where you want to take this.

  1. I noticed that you need to hardcode the config key into any warnings (see this example) . This is bad as the same ConfigOption class could be used for more than one key (for example, if the Type or URL types raised a warning). base.Config._validate does the right thing with errors and uses the current key (see L51). The same thing should happen for errors two lines above.
  2. Why don't warnings actually use warnings? Why not follow the pattern used for errors and define a ValidationWarning which subclasses warnings.Warning. Then within the code call raise ValidationWarning('some message...') and in base.Config._validate add a catch for warnings in addition to the current catch for errors. Using the same API for both warnings and errors seems more sensible to me (and easier to remember).
  3. Why are the errors being obscured? Only the message from the error is saved (see L51) and then later a new error is raised (see L148). Wouldn't it be better if the errors themselves were saved and re-raised? It would certainly help with debugging. Yes, I realize that if multiple errors were raised, only one could get re-raised. Not sure what the best solution is here for errors. Maybe log all the errors and then raise the first one? At least that way the user can work through them one at a time if the traceback is needed to figure out what went wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions