From ab04d74a5e88a2e951cee9c401a2450afa871c7f Mon Sep 17 00:00:00 2001 From: Harry Date: Fri, 1 Nov 2024 12:24:37 +0000 Subject: [PATCH] Make no-idea errors less patronising --- invoke/collection.py | 2 +- invoke/parser/parser.py | 2 +- invoke/program.py | 2 +- sites/docs/concepts/library.rst | 2 +- tests/program.py | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/invoke/collection.py b/invoke/collection.py index 23dcff928..e8e2e3d98 100644 --- a/invoke/collection.py +++ b/invoke/collection.py @@ -120,7 +120,7 @@ def _add_object(self, obj: Any, name: Optional[str] = None) -> None: elif isinstance(obj, (Collection, ModuleType)): method = self.add_collection else: - raise TypeError("No idea how to insert {!r}!".format(type(obj))) + raise TypeError("Cannot insert {!r}.".format(type(obj))) method(obj, name=name) def __repr__(self) -> str: diff --git a/invoke/parser/parser.py b/invoke/parser/parser.py index 43e95df04..f3912f77e 100644 --- a/invoke/parser/parser.py +++ b/invoke/parser/parser.py @@ -322,7 +322,7 @@ def handle(self, token: str) -> None: else: if not self.ignore_unknown: debug("Can't find context named {!r}, erroring".format(token)) - self.error("No idea what {!r} is!".format(token)) + self.error("Flag {!r} not recognised".format(token)) else: debug("Bottom-of-handle() see_unknown({!r})".format(token)) self.see_unknown(token) diff --git a/invoke/program.py b/invoke/program.py index c7e5cd004..97cc0c01b 100644 --- a/invoke/program.py +++ b/invoke/program.py @@ -511,7 +511,7 @@ def parse_cleanup(self) -> None: else: # TODO: feels real dumb to factor this out of Parser, but...we # should? - raise ParseError("No idea what '{}' is!".format(halp)) + raise ParseError("'{}' command not recognised.".format(halp)) # Print discovered tasks if necessary list_root = self.args.list.value # will be True or string diff --git a/sites/docs/concepts/library.rst b/sites/docs/concepts/library.rst index 1eeb55375..cd4254a75 100644 --- a/sites/docs/concepts/library.rst +++ b/sites/docs/concepts/library.rst @@ -140,7 +140,7 @@ The result? integration $ tester --list - No idea what '--list' is! + Command '--list' not recognised. $ tester unit Running unit tests! diff --git a/tests/program.py b/tests/program.py index 2d249b1fb..ec3c3bb58 100644 --- a/tests/program.py +++ b/tests/program.py @@ -360,7 +360,7 @@ def seeks_and_loads_tasks_module_by_default(self): def does_not_seek_tasks_module_if_namespace_was_given(self): expect( "foo", - err="No idea what 'foo' is!\n", + err="Task 'foo' not recognised.", program=Program(namespace=Collection("blank")), ) @@ -399,10 +399,10 @@ def ParseErrors_display_message_and_exit_1(self, mock_exit): nah = "nopenotvalidsorry" p.run("myapp {}".format(nah)) # Expect that we did print the core body of the ParseError (e.g. - # "no idea what foo is!") and exit 1. (Intent is to display that + # "Command 'foo' not recognised.") and exit 1. (Intent is to display that # info w/o a full traceback, basically.) stderr = sys.stderr.getvalue() - assert stderr == "No idea what '{}' is!\n".format(nah) + assert stderr == "Command '{}' not recognised.\n".format(nah) mock_exit.assert_called_with(1) @trap @@ -736,7 +736,7 @@ def exits_after_printing(self): expect("-c decorators -h punch --list", out=expected) def complains_if_given_invalid_task_name(self): - expect("-h this", err="No idea what 'this' is!\n") + expect("-h this", err="Task 'this' not recognised.\n") class task_list: "--list"