Skip to content

Fix broad exception handling in CLI step lookup and resume run-id validation#3179

Open
LuisJG8 wants to merge 1 commit intoNetflix:masterfrom
LuisJG8:fix/cli-staged-cleanups
Open

Fix broad exception handling in CLI step lookup and resume run-id validation#3179
LuisJG8 wants to merge 1 commit intoNetflix:masterfrom
LuisJG8:fix/cli-staged-cleanups

Conversation

@LuisJG8
Copy link
Copy Markdown

@LuisJG8 LuisJG8 commented May 6, 2026

PR Type

  • Bug fix
  • New feature
  • Core Runtime change (higher bar -- see CONTRIBUTING.md)
  • Docs / tooling
  • Refactoring

Summary

Hi, this PR fixes CLI error-handling behavior in two command paths.

In metaflow/cli_components/step_cmd.py, the step lookup now catches only AttributeError when a step is missing, instead of a bare except. In metaflow/cli_components/run_cmds.py, run_id validation now catches only TypeError and ValueError when checking whether the value is an integer.

I added these changes to prevent unrelated internal exceptions from being swallowed and reported as user-facing command errors, while preserving existing CLI behavior for valid and invalid inputs.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 6, 2026

Greptile Summary

This PR tightens two overly broad except: clauses in CLI command handlers, replacing them with the specific exception types each code path is actually expected to raise.

  • In run_cmds.py, the int(run_id) conversion now catches only TypeError and ValueError, which are the only exceptions that can realistically arise when converting a CLI string argument to an integer.
  • In step_cmd.py, the getattr call now catches only AttributeError, which is the precise exception raised when a flow attribute (step) does not exist.

Confidence Score: 5/5

Safe to merge — both changes are minimal, targeted narrowings of exception scope with no behavioral change on the happy path.

Both changes correctly identify the expected exceptions for their respective operations: ValueError/TypeError for int() conversion of a string, and AttributeError for a missing getattr result. No logic is altered, no new code paths are introduced, and the fix prevents real internal exceptions from being silently swallowed and misreported as user-facing CLI errors.

No files require special attention.

Important Files Changed

Filename Overview
metaflow/cli_components/run_cmds.py Narrows bare except: to except (TypeError, ValueError): when calling int(run_id) — correct set of exceptions for integer conversion of a CLI string argument.
metaflow/cli_components/step_cmd.py Narrows bare except: to except AttributeError: on getattr call — correctly targets the only exception getattr raises when an attribute is absent.

Reviews (1): Last reviewed commit: "Narrow CLI exception handling in step/re..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant