Skip to content
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
8 changes: 8 additions & 0 deletions c/driver_manager/adbc_driver_manager_driver_loading.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ AdbcStatusCode LoadDriverManifest(const std::filesystem::path& driver_manifest,
// differentiate between bad syntax and other I/O error.
std::string message = "Could not open manifest. ";
message += err.what();
const auto& src = err.source();
if (src.begin) {
message += " (line ";
message += std::to_string(src.begin.line);
message += ", column ";
message += std::to_string(src.begin.column);
message += ")";
}
message += ". Manifest: ";
message += driver_manifest.string();
SetError(error, std::move(message));
Expand Down
8 changes: 8 additions & 0 deletions c/driver_manager/adbc_driver_manager_profiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ AdbcStatusCode LoadProfileFile(const std::filesystem::path& profile_path,
} catch (const toml::parse_error& err) {
std::string message = "Could not open profile. ";
message += err.what();
const auto& src = err.source();
if (src.begin) {
message += " (line ";
message += std::to_string(src.begin.line);
message += ", column ";
message += std::to_string(src.begin.column);
message += ")";
}
message += ". Profile: ";
message += profile_path.string();
SetError(error, std::move(message));
Expand Down
40 changes: 40 additions & 0 deletions c/driver_manager/adbc_driver_manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,46 @@ TEST_F(ConnectionProfiles, CustomProfileProvider) {
ASSERT_THAT(AdbcDatabaseRelease(&database.value, &error), IsOkStatus(&error));
}

TEST_F(ConnectionProfiles, ProfileParseErrorIncludesLocation) {
auto filepath = temp_dir / "badprofile.toml";
std::ofstream file(filepath);
ASSERT_TRUE(file.is_open());
file << "profile_version = 1\n"
<< "driver = unquoted_value\n"
<< "[Options]\n";
file.close();

adbc_validation::Handle<struct AdbcDatabase> database;
ASSERT_THAT(AdbcDatabaseNew(&database.value, &error), IsOkStatus(&error));
ASSERT_THAT(AdbcDatabaseSetOption(&database.value, "profile", filepath.string().c_str(),
&error),
IsOkStatus(&error));
ASSERT_THAT(AdbcDatabaseInit(&database.value, &error),
IsStatus(ADBC_STATUS_INVALID_ARGUMENT, &error));
ASSERT_THAT(error.message, ::testing::HasSubstr("line 2"));
ASSERT_THAT(error.message, ::testing::HasSubstr("column"));
ASSERT_THAT(AdbcDatabaseRelease(&database.value, &error), IsOkStatus(&error));
}

TEST_F(DriverManifest, ManifestParseErrorIncludesLocation) {
std::ofstream file(temp_dir / "baddriver.toml");
ASSERT_TRUE(file.is_open());
file << "manifest_version = 1\n"
<< "[Driver]\n"
<< "shared = unquoted_value\n";
file.close();

SetDriverPath(temp_dir.string().c_str());

ASSERT_THAT(AdbcFindLoadDriver("baddriver", nullptr, ADBC_VERSION_1_1_0,
ADBC_LOAD_FLAG_DEFAULT, nullptr, &driver, &error),
IsStatus(ADBC_STATUS_INVALID_ARGUMENT, &error));
ASSERT_THAT(error.message, ::testing::HasSubstr("line 3"));
ASSERT_THAT(error.message, ::testing::HasSubstr("column"));

UnsetDriverPath();
}

struct DriverUriProfile {
std::string name;
std::string driver;
Expand Down
8 changes: 8 additions & 0 deletions go/adbc/drivermgr/adbc_driver_manager_driver_loading.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions go/adbc/drivermgr/adbc_driver_manager_profiles.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions python/adbc_driver_manager/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,21 @@ def test_version_invalid(tmp_path, monkeypatch) -> None:
pass


def test_parse_error_includes_location(tmp_path, monkeypatch) -> None:
# Test that TOML parse errors include line/column information
monkeypatch.setenv("ADBC_PROFILE_PATH", str(tmp_path))

with (tmp_path / "badtoml.toml").open("w") as sink:
sink.write("""profile_version = 1
driver = unquoted_value
[Options]
""")

with pytest.raises(dbapi.ProgrammingError, match=r"line 2.*column"):
with dbapi.connect("profile://badtoml"):
pass


def test_reject_malformed(tmp_path, monkeypatch) -> None:
# Test that invalid profiles are rejected
monkeypatch.setenv("ADBC_PROFILE_PATH", str(tmp_path))
Expand Down Expand Up @@ -448,6 +463,23 @@ def test_load_driver_manifest(tmp_path, monkeypatch) -> None:
assert cursor.fetchone() is not None


def test_manifest_parse_error_includes_location(tmp_path, monkeypatch) -> None:
# Test that TOML parse errors in manifests include line/column information
manifest_path = tmp_path / "manifest"
manifest_path.mkdir()
monkeypatch.setenv("ADBC_DRIVER_PATH", str(manifest_path))

with (manifest_path / "badmanifest.toml").open("w") as sink:
sink.write("""manifest_version = 1
[Driver]
shared = unquoted_value
""")

with pytest.raises(dbapi.ProgrammingError, match=r"line 3.*column"):
with dbapi.connect("badmanifest"):
pass


def test_subdir(monkeypatch, tmp_path) -> None:
# Test that we can search in subdirectories
monkeypatch.setenv("ADBC_PROFILE_PATH", str(tmp_path))
Expand Down
Loading