Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Error Message When Reading Invalid Files #230

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions thicket/tests/test_reader_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# SPDX-License-Identifier: MIT

import os
import pytest

from hatchet import GraphFrame
Expand Down Expand Up @@ -88,3 +89,34 @@ def test_valid_inputs(rajaperf_cali_1trial, data_dir):
True,
f"{data_dir}/rajaperf/lassen/clang10.0.1_nvcc10.2.89_1048576/1/",
)


def test_error_file(mpi_scaling_cali, data_dir):

# Create a temporarily empty file
empty_file_path = os.path.join(f"{data_dir}/mpi_scaling_cali", "empty.cali")
with open(empty_file_path, "w"):
pass # This creates an empty file

# list
with pytest.raises(Exception, match="Failed to read file"):
Thicket.reader_dispatch(
GraphFrame.from_caliperreader,
False,
True,
True,
mpi_scaling_cali + [empty_file_path],
)

# directory
with pytest.raises(Exception, match="Failed to read file"):
Thicket.reader_dispatch(
GraphFrame.from_caliperreader,
False,
True,
True,
f"{data_dir}/mpi_scaling_cali/",
)

# Remove the file
os.remove(empty_file_path)
18 changes: 10 additions & 8 deletions thicket/thicket.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,20 +437,22 @@ def reader_dispatch(
pbar = tqdm.tqdm(obj, disable=disable_tqdm)
for file in pbar:
pbar.set_description(pbar_desc)
ens_list.append(
Thicket.thicketize_graphframe(
func(file, *extra_args, **kwargs), file
)
)
try:
gf = func(file, *extra_args, **kwargs)
except Exception as e:
raise Exception(f"Failed to read file: {file}") from e
ens_list.append(Thicket.thicketize_graphframe(gf, file))
# if directory of files
elif os.path.isdir(obj):
pbar = tqdm.tqdm(os.listdir(obj), disable=disable_tqdm)
for file in pbar:
pbar.set_description(pbar_desc)
f = os.path.join(obj, file)
ens_list.append(
Thicket.thicketize_graphframe(func(f, *extra_args, **kwargs), f)
)
try:
gf = func(f, *extra_args, **kwargs)
except Exception as e:
raise Exception(f"Failed to read file: {f}") from e
ens_list.append(Thicket.thicketize_graphframe(gf, f))
# if single file
elif os.path.isfile(obj):
return Thicket.thicketize_graphframe(func(*args, **kwargs), args[0])
Expand Down
Loading