aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-05-08 09:18:31 +0200
committerGitHub <[email protected]>2023-05-08 09:18:31 +0200
commitb4dd4279139f6496eace81723d0b20aa1275324e (patch)
treeccd102edcbea9e127ee11a3cf890f00ceb15ad35 /src
parent247 complete httpclient implementation (#269) (diff)
downloadzen-b4dd4279139f6496eace81723d0b20aa1275324e.tar.xz
zen-b4dd4279139f6496eace81723d0b20aa1275324e.zip
replace use of cxxopts::OptionParseException in our code
later versions of cxxopts changed the signatures of exceptions. This change adds zen::OptionParseException to replace it
Diffstat (limited to 'src')
-rw-r--r--src/zen/chunk/chunk.cpp4
-rw-r--r--src/zen/cmds/cache.cpp3
-rw-r--r--src/zen/cmds/hash.cpp2
-rw-r--r--src/zen/cmds/projectstore.cpp2
-rw-r--r--src/zen/cmds/rpcreplay.cpp4
-rw-r--r--src/zen/zen.cpp18
-rw-r--r--src/zen/zen.h4
-rw-r--r--src/zencore/include/zencore/except.h8
-rw-r--r--src/zenserver/config.cpp13
9 files changed, 47 insertions, 11 deletions
diff --git a/src/zen/chunk/chunk.cpp b/src/zen/chunk/chunk.cpp
index d3591f8ca..81dde4c6a 100644
--- a/src/zen/chunk/chunk.cpp
+++ b/src/zen/chunk/chunk.cpp
@@ -986,10 +986,10 @@ ChunkCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
bool IsValid = m_ScanDirectory.length();
if (!IsValid)
- throw cxxopts::OptionParseException("Chunk command requires a directory to scan");
+ throw zen::OptionParseException("Chunk command requires a directory to scan");
if ((m_ChunkSize && m_AverageChunkSize) && (!m_ChunkSize && !m_AverageChunkSize))
- throw cxxopts::OptionParseException("Either of --chunk-size or --average-chunk-size must be used");
+ throw zen::OptionParseException("Either of --chunk-size or --average-chunk-size must be used");
std::unique_ptr<zen::CasStore> CasStore;
diff --git a/src/zen/cmds/cache.cpp b/src/zen/cmds/cache.cpp
index 495662d2f..0de3f8bc3 100644
--- a/src/zen/cmds/cache.cpp
+++ b/src/zen/cmds/cache.cpp
@@ -2,6 +2,7 @@
#include "cache.h"
+#include <zencore/except.h>
#include <zencore/filesystem.h>
#include <zencore/logging.h>
#include <zenhttp/httpcommon.h>
@@ -36,7 +37,7 @@ DropCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (m_NamespaceName.empty())
{
- throw cxxopts::OptionParseException("Drop command requires a namespace");
+ throw zen::OptionParseException("Drop command requires a namespace");
}
cpr::Session Session;
diff --git a/src/zen/cmds/hash.cpp b/src/zen/cmds/hash.cpp
index 7987d7738..cc59ed46e 100644
--- a/src/zen/cmds/hash.cpp
+++ b/src/zen/cmds/hash.cpp
@@ -73,7 +73,7 @@ HashCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
bool valid = m_ScanDirectory.length();
if (!valid)
- throw cxxopts::OptionParseException("Hash command requires a directory to scan");
+ throw zen::OptionParseException("Hash command requires a directory to scan");
// Gather list of files to process
diff --git a/src/zen/cmds/projectstore.cpp b/src/zen/cmds/projectstore.cpp
index fe0dd713e..9db7a4841 100644
--- a/src/zen/cmds/projectstore.cpp
+++ b/src/zen/cmds/projectstore.cpp
@@ -51,7 +51,7 @@ DropProjectCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg
if (m_ProjectName.empty())
{
- throw cxxopts::OptionParseException("Drop command requires a project");
+ throw zen::OptionParseException("Drop command requires a project");
}
cpr::Session Session;
diff --git a/src/zen/cmds/rpcreplay.cpp b/src/zen/cmds/rpcreplay.cpp
index 9bc4b2c7b..b99c63962 100644
--- a/src/zen/cmds/rpcreplay.cpp
+++ b/src/zen/cmds/rpcreplay.cpp
@@ -47,7 +47,7 @@ RpcStartRecordingCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char
if (m_RecordingPath.empty())
{
- throw cxxopts::OptionParseException("Rpc start recording command requires a path");
+ throw zen::OptionParseException("Rpc start recording command requires a path");
}
cpr::Session Session;
@@ -168,7 +168,7 @@ RpcReplayCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
if (m_RecordingPath.empty())
{
- throw cxxopts::OptionParseException("Rpc replay command requires a path");
+ throw zen::OptionParseException("Rpc replay command requires a path");
}
if (m_OnHost)
diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp
index 9754f4434..7f0549d42 100644
--- a/src/zen/zen.cpp
+++ b/src/zen/zen.cpp
@@ -69,7 +69,7 @@ ZenCmdBase::ParseOptions(int argc, char** argv)
First = false;
}
- throw cxxopts::OptionParseException(fmt::format("Invalid arguments: {}", StringBuilder.ToView()));
+ throw zen::OptionParseException(fmt::format("Invalid arguments: {}", StringBuilder.ToView()));
}
return true;
@@ -397,6 +397,14 @@ main(int argc, char** argv)
exit(11);
}
+ catch (OptionParseException& Ex)
+ {
+ std::string help = VerbOptions.help();
+
+ printf("Error parsing arguments for command '%s': %s\n\n%s", SubCommand.c_str(), Ex.what(), help.c_str());
+
+ exit(11);
+ }
}
}
@@ -410,6 +418,14 @@ main(int argc, char** argv)
return 9;
}
+ catch (OptionParseException& Ex)
+ {
+ std::string HelpMessage = Options.help();
+
+ printf("Error parsing program arguments: %s\n\n%s", Ex.what(), HelpMessage.c_str());
+
+ return 9;
+ }
catch (std::exception& Ex)
{
printf("Exception caught from 'main': %s\n", Ex.what());
diff --git a/src/zen/zen.h b/src/zen/zen.h
index b55e7a16c..f6c2d8ff0 100644
--- a/src/zen/zen.h
+++ b/src/zen/zen.h
@@ -2,6 +2,7 @@
#pragma once
+#include <zencore/except.h>
#include <zencore/zencore.h>
ZEN_THIRD_PARTY_INCLUDES_START
@@ -26,6 +27,9 @@ struct ZenCliOptions
std::vector<std::string> PassthroughV;
};
+/** Base class for command implementations
+ */
+
class ZenCmdBase
{
public:
diff --git a/src/zencore/include/zencore/except.h b/src/zencore/include/zencore/except.h
index c61db5ba9..d3269f33a 100644
--- a/src/zencore/include/zencore/except.h
+++ b/src/zencore/include/zencore/except.h
@@ -54,4 +54,12 @@ MakeErrorCodeFromLastError() noexcept
return std::error_code(zen::GetLastError(), std::system_category());
}
+//////////////////////////////////////////////////////////////////////////
+
+class OptionParseException : public std::runtime_error
+{
+public:
+ inline explicit OptionParseException(const std::string& Message) : std::runtime_error(Message) {}
+};
+
} // namespace zen
diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp
index d28262607..08ef17c12 100644
--- a/src/zenserver/config.cpp
+++ b/src/zenserver/config.cpp
@@ -5,6 +5,7 @@
#include "diag/logging.h"
#include <zencore/crypto.h>
+#include <zencore/except.h>
#include <zencore/fmtutils.h>
#include <zencore/iobuffer.h>
#include <zencore/string.h>
@@ -69,7 +70,7 @@ ValidateOptions(ZenServerOptions& ServerOptions)
if (Key.IsValid() == false)
{
- throw cxxopts::OptionParseException("Invalid AES encryption key");
+ throw zen::OptionParseException("Invalid AES encryption key");
}
}
@@ -79,7 +80,7 @@ ValidateOptions(ZenServerOptions& ServerOptions)
if (IV.IsValid() == false)
{
- throw cxxopts::OptionParseException("Invalid AES initialization vector");
+ throw zen::OptionParseException("Invalid AES initialization vector");
}
}
}
@@ -581,7 +582,7 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
{
if (OpenIdClientId.empty())
{
- throw cxxopts::OptionParseException("Invalid OpenID client ID");
+ throw zen::OptionParseException("Invalid OpenID client ID");
}
ServerOptions.AuthConfig.OpenIdProviders.push_back(
@@ -607,6 +608,12 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
throw;
}
+ catch (zen::OptionParseException& e)
+ {
+ zen::logging::ConsoleLog().error("Error parsing zenserver arguments: {}\n\n{}", e.what(), options.help());
+
+ throw;
+ }
if (ServerOptions.DataDir.empty())
{