Skip to content

fix(client): give specific error for blank/whitespace pathspec components#3261

Open
dheerenmohta wants to merge 1 commit into
Netflix:masterfrom
dheerenmohta:fix/client-pathspec-misleading-whitespace-error
Open

fix(client): give specific error for blank/whitespace pathspec components#3261
dheerenmohta wants to merge 1 commit into
Netflix:masterfrom
dheerenmohta:fix/client-pathspec-misleading-whitespace-error

Conversation

@dheerenmohta

Copy link
Copy Markdown
Contributor

Problem

When a pathspec contains a whitespace-only component (e.g. "Flow/ /Step"), the existing code produces a confusing error:

  • If the whitespace-only component causes a wrong count → the error says "Expects Run(...)" — no mention of the blank segment
  • If there are the right number of components → no error at all (whitespace passes str.split("/") silently)

In both cases the user has no clear signal about what is wrong.

Fix

Add an explicit check before the component-count validation that:

  1. Finds all blank or whitespace-only component positions
  2. Raises MetaflowInvalidPathspec with the offending position(s) called out
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. ..."
        % (pathspec, ...)
    )

No behaviour change for valid pathspecs.

Fixes #948 (partial — error message quality)

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 Netflix#948 (partial)
@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an explicit check for blank or whitespace-only components in a pathspec string before the existing length validation, raising MetaflowInvalidPathspec with the affected position(s) clearly called out. Valid pathspecs are unaffected.

  • Inserts a list comprehension to collect 0-indexed positions of blank components from ids and raises a descriptive error immediately, so users get actionable feedback instead of a confusing "Expects Run(...)" message or silent acceptance.
  • Covers both empty ("Flow//Step") and whitespace-only ("Flow/ /Step") components, as well as leading/trailing slashes and wholly-blank pathspecs.

Confidence Score: 4/5

Safe to merge; the change is a small guard that fires only when a pathspec contains a blank component, leaving all valid pathspecs completely unchanged.

The fix is logically correct and well-placed, with one minor UX note: positions in the error message are 0-indexed, which may be slightly confusing for users who think of path components as starting at 1.

No files require special attention beyond the single changed guard in metaflow/client/core.py.

Important Files Changed

Filename Overview
metaflow/client/core.py Adds a blank/whitespace component check before the length validation in MetaflowObject.init, raising MetaflowInvalidPathspec with the offending 0-indexed position(s). Logic is correct; one minor UX note on 0-indexed position reporting.

Reviews (1): Last reviewed commit: "fix(client): improve error message for b..." | Re-trigger Greptile

Comment thread metaflow/client/core.py
Comment on lines +328 to +332
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))
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The positions are reported as 0-based indices, but end-users mentally count path components from 1 (e.g., "Flow/ /Step" — component 2 is blank, not component 1). Using 1-based positions in the error message would be more intuitive here.

Suggested change
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))
)
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 + 1) for p in blank))
)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@dddc0d5). Learn more about missing BASE report.

Files with missing lines Patch % Lines
metaflow/client/core.py 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3261   +/-   ##
=========================================
  Coverage          ?   29.08%           
=========================================
  Files             ?      381           
  Lines             ?    52516           
  Branches          ?     9267           
=========================================
  Hits              ?    15275           
  Misses            ?    36204           
  Partials          ?     1037           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Pathspec to create Flow/Run/Step/Task/DataArtifact is not validated

1 participant