From d67110be09cde41a9df99fbaea68a68073265b88 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 23 Oct 2019 12:15:17 +0200 Subject: [PATCH] Improve error messages --- royalnet/commands/commandargs.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/royalnet/commands/commandargs.py b/royalnet/commands/commandargs.py index c21e0b59..39d91723 100644 --- a/royalnet/commands/commandargs.py +++ b/royalnet/commands/commandargs.py @@ -15,12 +15,12 @@ class CommandArgs(list): try: return super().__getitem__(item) except IndexError: - raise InvalidInputError(f'Tried to get missing [{item}] arg from CommandArgs') + raise InvalidInputError(f'Missing argument #{item+1}.') if isinstance(item, slice): try: return super().__getitem__(item) except IndexError: - raise InvalidInputError(f'Tried to get invalid [{item}] slice from CommandArgs') + raise InvalidInputError(f'Cannot get arguments from #{item.start+1} to #{item.stop+1}.') raise ValueError(f"Invalid type passed to CommandArgs.__getattr__: {type(item)}") def joined(self, *, require_at_least=0) -> str: @@ -35,7 +35,7 @@ class CommandArgs(list): Returns: The space-joined string.""" if len(self) < require_at_least: - raise InvalidInputError("Not enough arguments") + raise InvalidInputError(f"Not enough arguments specified (minimum is {require_at_least}).") return " ".join(self) def match(self, pattern: typing.Union[str, typing.Pattern], *flags) -> typing.Sequence[typing.AnyStr]: @@ -52,7 +52,7 @@ class CommandArgs(list): text = self.joined() match = re.match(pattern, text, *flags) if match is None: - raise InvalidInputError("Pattern didn't match") + raise InvalidInputError("Invalid syntax.") return match.groups() def optional(self, index: int, default=None):