Skip to content

Commit 4a78071

Browse files
committed
fix: raise CodeBundleError for a missing include on the copy_style="none" path
`ls_relative_files` is the third site in `_code_bundle/_utils.py` that rejects an `Environment.include` entry, and the only one still raising a bare `ValueError`. It is reached from `build_code_bundle(copy_style="none", additional_files=...)` via `build_code_bundle_from_relative_paths` -> `list_relative_files_to_bundle`, so the path it complains about came straight from the user's `include=`. Same reasoning as the two sites already converted in this PR: an include that matches no file, directory or glob is the user's configuration, not an SDK bug, so it should be a typed user error that crash reporting filters out instead of a raw `ValueError` reported as a crash. The message is also reworded from "File ... is not a valid file, directory, or glob pattern" to name the concept the user actually typed ("include path ..."), matching its sibling in `ls_files`. fixes FLYTE-SDK-5M Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
1 parent 8aa48d7 commit 4a78071

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/flyte/_code_bundle/_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,13 @@ def ls_relative_files(relative_paths: list[str], source_path: pathlib.Path) -> t
231231
# Filter out directories from glob results
232232
all_files.extend([str(f) for f in glob_files if pathlib.Path(f).is_file()])
233233
else:
234-
raise ValueError(f"File {path} is not a valid file, directory, or glob pattern")
234+
from flyte.errors import CodeBundleError
235+
236+
# Same user error as the `additional_files` branch of `ls_files` above,
237+
# reached by the `copy_style="none"` bundle path: the entry came from the
238+
# user's `Environment.include`, so a path that matches nothing is their
239+
# configuration, not an SDK bug (FLYTE-SDK-5M).
240+
raise CodeBundleError(f"include path {str(path)!r} is not a file, directory, or glob pattern.")
235241

236242
all_files.sort()
237243
abs_source = os.path.abspath(str(source_path))

tests/flyte/code_bundle/test_build_code_bundle.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,28 @@ async def test_build_code_bundle_include_outside_source_raises():
441441
)
442442

443443

444+
@pytest.mark.asyncio
445+
async def test_build_code_bundle_copy_style_none_missing_include_raises():
446+
"""
447+
A ``copy_style='none'`` include that matches nothing must fail with the same
448+
typed user error as the ``copy_style='all'`` path. This route reaches
449+
``ls_relative_files`` instead of ``ls_files``, and used to raise a bare
450+
``ValueError`` that was crash-reported as an SDK bug.
451+
"""
452+
with tempfile.TemporaryDirectory() as tmp:
453+
tmp_dir = Path(tmp)
454+
layout = _copy_layout("single_file", tmp_dir)
455+
456+
with pytest.raises(CodeBundleError, match="is not a file, directory, or glob pattern"):
457+
await build_code_bundle(
458+
from_dir=layout,
459+
dryrun=True,
460+
copy_style="none",
461+
additional_files=(str(layout / "does_not_exist.yaml"),),
462+
copy_bundle_to=_bundle_out(tmp_dir),
463+
)
464+
465+
444466
@pytest.mark.asyncio
445467
async def test_build_code_bundle_empty_source_raises(tmp_path):
446468
"""An empty source directory with copy_style='all' surfaces a clear error."""

tests/flyte/code_bundle/test_code_bundle.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,17 @@ def test_ls_relative_files_with_mixed_inputs():
234234

235235

236236
def test_ls_relative_files_invalid_path():
237-
"""Test ls_relative_files raises ValueError for invalid paths."""
237+
"""Test ls_relative_files raises CodeBundleError for invalid paths."""
238+
from flyte.errors import CodeBundleError
239+
238240
with tempfile.TemporaryDirectory() as tmpdir:
239241
test_dir = pathlib.Path(tmpdir)
240242

241243
# Create a valid file
242244
(test_dir / "main.py").write_text("print('hello')")
243245

244246
# Test with non-existent path that doesn't match any glob
245-
with pytest.raises(ValueError, match="is not a valid file, directory, or glob pattern"):
247+
with pytest.raises(CodeBundleError, match="is not a file, directory, or glob pattern"):
246248
ls_relative_files(["nonexistent.py"], test_dir)
247249

248250

0 commit comments

Comments
 (0)