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

Fix issue 1033 #1145

Merged
merged 1 commit into from
Jan 4, 2023
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
16 changes: 11 additions & 5 deletions src/common/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ void FileUtils::readFromFile(
}

void FileUtils::createDir(const string& dir) {
if (filesystem::exists(dir)) {
throw Exception(StringUtils::string_format("Directory %s already exists.", dir.c_str()));
}
if (!filesystem::create_directory(dir)) {
try {
if (filesystem::exists(dir)) {
throw Exception(
StringUtils::string_format("Directory %s already exists.", dir.c_str()));
}
if (!filesystem::create_directory(dir)) {
throw Exception(StringUtils::string_format(
"Directory %s cannot be created. Check if it exists and remove it.", dir.c_str()));
}
} catch (exception& e) {
throw Exception(StringUtils::string_format(
"Directory %s cannot be created. Check if it exists and remove it.", dir.c_str()));
"Failed to create directory %s due to: %s", dir.c_str(), e.what()));
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/main/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ TEST_F(ApiTest, ClientConfig) {
ASSERT_NO_THROW(conn->setMaxNumThreadForExec(2));
ASSERT_EQ(conn->getMaxNumThreadForExec(), 2);
}

TEST_F(ApiTest, DatabasePathIncorrect) {
spdlog::set_level(spdlog::level::debug);
try {
make_unique<Database>(DatabaseConfig("/\\0:* /? \" < > |"));
FAIL();
} catch (Exception& e) {
ASSERT_TRUE(string(e.what()).find("Failed to create directory") != string::npos);
}
}
9 changes: 9 additions & 0 deletions tools/python_api/test/test_exception.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import pytest
import sys
sys.path.append('../build/')
Copy link
Contributor

Choose a reason for hiding this comment

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

double check if this is needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes seems to be required, the tests failed after I removed it: https://github.com/kuzudb/kuzu/actions/runs/3838919604/jobs/6535990703

import kuzu


def test_exception(establish_connection):
Expand All @@ -13,3 +16,9 @@ def test_exception(establish_connection):
with pytest.raises(RuntimeError,
match="Buffer manager exception: Resizing to a smaller Buffer Pool Size is unsupported."):
db.resize_buffer_manager(1)


def test_db_path_exception():
path = '/:* /? " < > |'
with pytest.raises(RuntimeError, match='filesystem error'):
kuzu.Database(str(path))
9 changes: 7 additions & 2 deletions tools/shell/shell_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ int main(int argc, char* argv[]) {
cout << "Enter \":help\" for usage hints." << endl;
SystemConfig systemConfig(bpSizeInMB << 20);
DatabaseConfig databaseConfig(databasePath, inMemoryFlag);
auto shell = EmbeddedShell(databaseConfig, systemConfig);
shell.run();
try {
auto shell = EmbeddedShell(databaseConfig, systemConfig);
shell.run();
} catch (exception &e) {
cerr << e.what() << endl;
return 1;
}
return 0;
}