Repository navigation
fix: correctly report type errors in config - #25
Merged
Merged
Conversation
Issue
-----
Currently, the types of fields in the configuration is validated when
the configuration is loaded. But the error is not reported correctly:
```
Traceback (most recent call last):
File "/home/cjoly/ghq/github.com/moverest/sway-interactive-screenshot/./sway-interactive-screenshot", line 922, in <module>
main()
~~~~^^
File "/home/cjoly/ghq/github.com/moverest/sway-interactive-screenshot/./sway-interactive-screenshot", line 830, in main
config = Config(args.config)
File "/home/cjoly/ghq/github.com/moverest/sway-interactive-screenshot/./sway-interactive-screenshot", line 174, in __init__
errors = list(self._validate("", self.config))
File "/home/cjoly/ghq/github.com/moverest/sway-interactive-screenshot/./sway-interactive-screenshot", line 58, in validate
yield from field_validators[field_name](f"{path}.{field_name}", field_value)
File "/home/cjoly/ghq/github.com/moverest/sway-interactive-screenshot/./sway-interactive-screenshot", line 58, in validate
yield from field_validators[field_name](f"{path}.{field_name}", field_value)
File "/home/cjoly/ghq/github.com/moverest/sway-interactive-screenshot/./sway-interactive-screenshot", line 68, in validate
path, f"Type {type(value)} is not one of {', '.join(types)}."
~~~~~~~~~^^^^^^^
TypeError: sequence item 0: expected str instance, type found
```
Here, an exception occurs when trying to instantiate `ValidationError`,
because the type `Type` is not a `str`, which `join` expects.
This MR fixes that, so we now print:
```
Traceback (most recent call last):
File "/home/cjoly/ghq/github.com/moverest/sway-interactive-screenshot/./sway-interactive-screenshot", line 922, in <module>
main()
~~~~^^
File "/home/cjoly/ghq/github.com/moverest/sway-interactive-screenshot/./sway-interactive-screenshot", line 830, in main
config = Config(args.config)
File "/home/cjoly/ghq/github.com/moverest/sway-interactive-screenshot/./sway-interactive-screenshot", line 176, in __init__
raise ConfigError(errors)
ConfigError: Config errors:
.screenshot.cursor: Type <class 'str'> is not one of <class 'bool'>.
```
Testing
-------
I triggered the error with the following config:
```toml
[screenshot]
cursor = "false2"
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Currently, the types of fields in the configuration is validated when
the configuration is loaded. But the error is not reported correctly:
Here, an exception occurs when trying to instantiate
ValidationError,because the type
Typeis not astr, whichjoinexpects.This MR fixes that, so we now print:
Testing
I triggered the error with the following config: