Skip to content

Commit

Permalink
Add check for program argument empty value
Browse files Browse the repository at this point in the history
  • Loading branch information
sitaowang1998 committed Feb 4, 2025
1 parent a365d7b commit df31fe2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/spider/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ auto parse_args(
}

boost::program_options::notify(variables);

if (host.empty()) {
std::cerr << spider::core::cHostEmptyMessage << "\n";
return false;
}

if (storage_url.empty()) {
std::cerr << spider::core::cStorageUrlEmptyMessage << "\n";
return false;
}

return true;
} catch (boost::program_options::error& e) {
std::cerr << "spider_scheduler: " << e.what() << "\n";
Expand Down
7 changes: 7 additions & 0 deletions src/spider/utils/ProgramOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ constexpr std::string_view cHostOption = {"host"};

constexpr std::string_view cHostMessage = {"The host address to bind to"};

constexpr std::string_view cHostEmptyMessage = {"The host address should not be empty"};

constexpr std::string_view cPortOption = {"port"};

constexpr std::string_view cPortMessage = {"The port to listen on"};
Expand All @@ -40,10 +42,15 @@ constexpr std::string_view cStorageUrlOption = {"storage-url"};

constexpr std::string_view cStorageUrlMessage = {"The storage server's URL"};

constexpr std::string_view cStorageUrlEmptyMessage
= {"The storage server's URL should not be empty"};

constexpr std::string_view cLibsOption = {"libs"};

constexpr std::string_view cLibsMessage = {"The tasks libraries to load"};

constexpr std::string_view cLibsEmptyMessage = {"The tasks libraries should not be empty"};

constexpr std::string_view cFunctionOption = {"func"};

constexpr std::string_view cFunctionMessage = {"The function to execute"};
Expand Down
16 changes: 16 additions & 0 deletions src/spider/worker/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ auto parse_args(
}

boost::program_options::notify(variables);

if (host.empty()) {
std::cerr << spider::core::cHostEmptyMessage << "\n";
return false;
}

if (storage_url.empty()) {
std::cerr << spider::core::cStorageUrlEmptyMessage << "\n";
return false;
}

if (libs.empty()) {
std::cerr << spider::core::cLibsEmptyMessage << "\n";
return false;
}

return true;
} catch (boost::program_options::error& e) {
std::cerr << "spider_worker: " << e.what() << "\n";
Expand Down

0 comments on commit df31fe2

Please sign in to comment.