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

GH-43967: [C++] Enhance error message for URI parsing #43938

Merged
merged 2 commits into from
Sep 5, 2024
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 cpp/src/arrow/filesystem/filesystem_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <utility>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "arrow/filesystem/filesystem.h"
Expand Down Expand Up @@ -632,6 +633,13 @@ TEST_F(TestMockFS, FileSystemFromUri) {
ASSERT_OK_AND_ASSIGN(fs_, FileSystemFromUri("mock:///foo/bar?q=zzz", &path));
ASSERT_EQ(path, "foo/bar");
CheckDirs({});
ASSERT_OK_AND_ASSIGN(fs_, FileSystemFromUri("mock:/folder+name/bar?q=zzz", &path));
AlenkaF marked this conversation as resolved.
Show resolved Hide resolved
ASSERT_EQ(path, "folder+name/bar");
CheckDirs({});
EXPECT_RAISES_WITH_MESSAGE_THAT(
Invalid, ::testing::HasSubstr("syntax error at character ' ' (position 12)"),
FileSystemFromUri("mock:/folder name/bar", &path));
CheckDirs({});
}

////////////////////////////////////////////////////////////////////////////
Expand Down
13 changes: 10 additions & 3 deletions cpp/src/arrow/util/uri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,16 @@ Status Uri::Parse(const std::string& uri_string) {
const auto& s = impl_->KeepString(uri_string);
impl_->string_rep_ = s;
const char* error_pos;
if (uriParseSingleUriExA(&impl_->uri_, s.data(), s.data() + s.size(), &error_pos) !=
URI_SUCCESS) {
return Status::Invalid("Cannot parse URI: '", uri_string, "'");
int retval =
uriParseSingleUriExA(&impl_->uri_, s.data(), s.data() + s.size(), &error_pos);
if (retval != URI_SUCCESS) {
if (retval == URI_ERROR_SYNTAX) {
return Status::Invalid("Cannot parse URI: '", uri_string,
"' due to syntax error at character '", *error_pos,
"' (position ", error_pos - s.data(), ")");
} else {
return Status::Invalid("Cannot parse URI: '", uri_string, "'");
}
}

const auto scheme = TextRangeToView(impl_->uri_.scheme);
Expand Down
Loading