From e18655787a64f88411a186db6f61f2b2dde2894b Mon Sep 17 00:00:00 2001 From: Dheeren Mohta Date: Thu, 11 Jun 2026 14:26:05 +0530 Subject: [PATCH] fix(client): improve error message for blank pathspec components When a pathspec like "Flow/ /Step" was passed (whitespace-only component), the existing code would either silently pass the split or produce a confusing wrong-component-count error, rather than identifying the real problem (blank/whitespace component). Add an explicit check that reports the exact position(s) of blank components before the length validation runs, giving users a clear, actionable error message. Fixes #948 (partial) --- metaflow/client/core.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/metaflow/client/core.py b/metaflow/client/core.py index 76b4a472316..40ca589c306 100644 --- a/metaflow/client/core.py +++ b/metaflow/client/core.py @@ -321,6 +321,16 @@ def __init__( if pathspec and _object is None: ids = pathspec.split("/") + # Reject blank components (empty string or whitespace-only), e.g. "Flow//Step" + # or "Flow/ /Step". Check before the length tests so the error is specific. + blank = [i for i, c in enumerate(ids) if not c.strip()] + if blank: + raise MetaflowInvalidPathspec( + "Pathspec '%s' has an empty or blank component at position(s) %s. " + "Each '/' must separate non-empty path parts." + % (pathspec, ", ".join(str(p) for p in blank)) + ) + if self._NAME == "flow" and len(ids) != 1: raise MetaflowInvalidPathspec("Expects Flow('FlowName')") elif self._NAME == "run" and len(ids) != 2: