Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dispatcher): explicitly disable exception chaining #240

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions craft_cli/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def _get_requested_help( # noqa: PLR0912 (too many branches)
except KeyError:
allowed = (repr(of.name) for of in OutputFormat)
msg = f"Invalid value for --format; allowed are: {', '.join(sorted(allowed))}"
raise self._build_usage_exc(msg) # noqa: TRY200 (Use `raise from`)
raise self._build_usage_exc(msg) from None

if len(filtered_params) == 1:
# at this point the remaining parameter should be a command
Expand All @@ -329,7 +329,7 @@ def _get_requested_help( # noqa: PLR0912 (too many branches)
cmd_class = self.commands[cmdname]
except KeyError:
msg = f"command {cmdname!r} not found to provide help for"
raise self._build_usage_exc(msg) # noqa: TRY200 (Use `raise from`)
raise self._build_usage_exc(msg) from None

# instantiate the command and fill its arguments
command = cmd_class(None)
Expand Down Expand Up @@ -402,7 +402,7 @@ def _parse_options( # noqa: PLR0912 (too many branches)
global_args[arg.name] = next(sysargs_it)
except StopIteration:
msg = f"The {arg.name!r} option expects one argument."
raise self._build_usage_exc(msg) # noqa: TRY200 (use 'raise from')
raise self._build_usage_exc(msg) from None
elif sysarg.startswith(tuple(options_with_equal)):
option, value = sysarg.split("=", 1)
arg = arg_per_option[option]
Expand Down Expand Up @@ -439,10 +439,10 @@ def pre_parse_args(self, sysargs: list[str]) -> dict[str, Any]:
try:
verbosity_level = EmitterMode[global_args["verbosity"].upper()]
except KeyError:
raise self._build_usage_exc( # noqa: TRY200 (use 'raise from')
raise self._build_usage_exc(
"Bad verbosity level; valid values are "
"'quiet', 'brief', 'verbose', 'debug' and 'trace'."
)
) from None
emit.set_mode(verbosity_level)
emit.trace(f"Raw pre-parsed sysargs: args={global_args} filtered={filtered_sysargs}")

Expand Down Expand Up @@ -474,7 +474,7 @@ def pre_parse_args(self, sysargs: list[str]) -> dict[str, Any]:
self._command_class = self.commands[command]
except KeyError:
help_text = self._build_no_command_error(command)
raise ArgumentParsingError(help_text) # noqa: TRY200 (use raise from)
raise ArgumentParsingError(help_text) from None

emit.trace(f"General parsed sysargs: command={ command!r} args={cmd_args}")
return global_args
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dev = [
lint = [
"black==24.2.0",
"codespell[toml]==2.2.6",
"ruff==0.1.15",
"ruff~=0.2.1",
"yamllint==1.34.0"
]
types = [
Expand Down Expand Up @@ -210,6 +210,7 @@ extend-select = [
"ANN0", # Type annotations for arguments other than `self` and `cls`
"ANN2", # Return type annotations
"B026", # Keyword arguments must come after starred arguments
"B904", # re-raising an exception should include a `from`.
# flake8-bandit: security testing. https://github.com/charliermarsh/ruff#flake8-bandit-s
# https://bandit.readthedocs.io/en/latest/plugins/index.html#complete-test-plugin-listing
"S101", "S102", # assert or exec
Expand Down
Loading