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
3 changes: 3 additions & 0 deletions src/hal/link/desktop/abstract-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const char* AbstractLink::_urlStringRegex = R"((?P<type>udp|serial):(?P<host>.*)
std::shared_ptr<AbstractLink> AbstractLink::openUrl(const std::string& url)
{
if (url.empty()) {
std::cerr << "Empty URL was provided when trying to open a link" << std::endl;
return {};
}

Expand All @@ -30,6 +31,7 @@ std::shared_ptr<AbstractLink> AbstractLink::openUrl(const std::string& url)
} urlStruct;

if (!regex_search(url, match, regex)) {
std::cerr << "Invalid URL provided, should be in format `type:host:config`" << std::endl;
return {};
}

Expand All @@ -46,5 +48,6 @@ std::shared_ptr<AbstractLink> AbstractLink::openUrl(const std::string& url)
return std::make_shared<UdpLink>(urlStruct.host, urlStruct.config);
}

std::cerr << "Unknown link type provided" << std::endl;
return {};
}
4 changes: 4 additions & 0 deletions test/test-device-ping1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ int main(int argc, char* argv[])
}

auto port = AbstractLink::openUrl(CommandLine::self()->connectionString);
if (!port) {
std::cerr << "Failed to open communication link with device" << std::endl;
return -1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to add a message inside the AbstractLink as well to print the reason

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added message in different return paths from openURL plus the failed to open since the regex can be valid and still fails to open the port.

}
Ping1d device = Ping1d(*port.get());

// Basic information
Expand Down
4 changes: 4 additions & 0 deletions test/test-device-ping360.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ int main(int argc, char* argv[])
}

auto port = AbstractLink::openUrl(CommandLine::self()->connectionString);
if (!port) {
std::cerr << "Failed to open communication link with device" << std::endl;
return -1;
}
Ping360 device = Ping360(*port.get());

// Basic information
Expand Down
4 changes: 4 additions & 0 deletions test/test-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ int main(int argc, char* argv[])
}

auto port = AbstractLink::openUrl(CommandLine::self()->connectionString);
if (!port) {
std::cerr << "Failed to open communication link with device" << std::endl;
return -1;
}
PingDevice device = PingDevice(*port.get());

// Basic information
Expand Down
Loading