Skip to content

Narrow exception handling in CLI plugin commands#3192

Open
LuisJG8 wants to merge 3 commits into
Netflix:masterfrom
LuisJG8:fix/staged-cli-plugin-cleanups
Open

Narrow exception handling in CLI plugin commands#3192
LuisJG8 wants to merge 3 commits into
Netflix:masterfrom
LuisJG8:fix/staged-cli-plugin-cleanups

Conversation

@LuisJG8
Copy link
Copy Markdown

@LuisJG8 LuisJG8 commented May 12, 2026

PR Type

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

Summary

This PR narrows broad exception handling in two CLI plugin paths. Replaced catch-all exception handling with more specific exception types in card rendering and logs command parsing.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 12, 2026

Greptile Summary

This refactoring replaces bare except: clauses with specific exception types across three CLI paths, improving debuggability without changing runtime behavior for the intended error cases.

  • run_cmds.py: int(run_id) now catches only (TypeError, ValueError), which are the exact exceptions int() raises for invalid input.
  • step_cmd.py: getattr(ctx.obj.flow, step_name) now catches only AttributeError; any other exception (e.g., from a property getter) will surface with an accurate traceback instead of the misleading "Step doesn't exist" message.
  • card_cli.py: except:except Exception: means KeyboardInterrupt and SystemExit during card rendering now propagate correctly rather than being silently swallowed.

Confidence Score: 5/5

Safe to merge — all three narrowings are correct for their call sites and improve error transparency without breaking any existing error-handling paths.

Each changed except clause now catches exactly the exceptions that the wrapped expression can raise under the documented failure condition. No silent swallowing of meaningful errors is introduced, and the fallback logic in each block remains intact.

No files require special attention.

Important Files Changed

Filename Overview
metaflow/cli_components/run_cmds.py Narrows bare except: to except (TypeError, ValueError): around int(run_id) — the only exceptions int() raises for bad input, making the change correct and complete.
metaflow/cli_components/step_cmd.py Narrows bare except: to except AttributeError: around getattr(ctx.obj.flow, step_name) — the expected exception when the attribute is absent; other exceptions will now propagate with accurate stack traces rather than a misleading "Step doesn't exist" message.
metaflow/plugins/cards/card_cli.py Replaces bare except: with except Exception: around card rendering — functionally identical for regular errors; KeyboardInterrupt/SystemExit now propagate instead of being silently swallowed, which is the correct behavior.

Reviews (2): Last reviewed commit: "Update metaflow/plugins/logs_cli.py" | Re-trigger Greptile

Comment thread metaflow/plugins/logs_cli.py Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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