Skip to content

Add error message for empty string in filedataloader. #10145

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

Merged
merged 1 commit into from
Apr 15, 2025
Merged
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
3 changes: 3 additions & 0 deletions extension/data_loader/file_data_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ Result<FileDataLoader> FileDataLoader::from(
"Alignment %zu is not a power of 2",
alignment);

ET_CHECK_OR_RETURN_ERROR(
file_name != nullptr, InvalidArgument, "File name cannot be empty.");

// Use open() instead of fopen() to avoid the layer of buffering that
// fopen() does. We will be reading large portions of the file in one shot,
// so buffering does not help.
Expand Down
6 changes: 6 additions & 0 deletions extension/data_loader/test/file_data_loader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ TEST_P(FileDataLoaderTest, FromMissingFileFails) {
EXPECT_NE(fdl.error(), Error::Ok);
}

TEST_P(FileDataLoaderTest, FromEmptyFilePathFails) {
// Nullptr should fail
Result<FileDataLoader> fdl = FileDataLoader::from(nullptr);
EXPECT_NE(fdl.error(), Error::Ok);
}

TEST_P(FileDataLoaderTest, BadAlignmentFails) {
// Create a temp file; contents don't matter.
uint8_t data[256] = {};
Expand Down
Loading