Make most command-line tools return useful error codes on well-known exceptions.
This commit is contained in:
committed by
Patrick Niklaus
parent
03e83ec6a0
commit
3d77714c36
@@ -108,7 +108,8 @@ int SourceContainer::LoadRasterSource(const std::string &path_string,
|
||||
boost::filesystem::path filepath(path_string);
|
||||
if (!boost::filesystem::exists(filepath))
|
||||
{
|
||||
throw util::exception(path_string + " does not exist" + SOURCE_REF);
|
||||
throw util::RuntimeError(
|
||||
path_string, ErrorCode::FileOpenError, SOURCE_REF, "File not found");
|
||||
}
|
||||
|
||||
RasterGrid rasterData{filepath, ncols, nrows};
|
||||
|
||||
+3
-1
@@ -36,7 +36,9 @@ OSRM::OSRM(engine::EngineConfig &config)
|
||||
// throw error if dataset is not usable with CoreCH
|
||||
if (config.algorithm == EngineConfig::Algorithm::CoreCH && !corech_compatible)
|
||||
{
|
||||
throw util::exception("Dataset is not compatible with CoreCH.");
|
||||
throw util::RuntimeError("Dataset is not compatible with CoreCH.",
|
||||
ErrorCode::IncompatibleDataset,
|
||||
SOURCE_REF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-1
@@ -1,6 +1,7 @@
|
||||
#include "storage/io.hpp"
|
||||
#include "osrm/contractor.hpp"
|
||||
#include "osrm/contractor_config.hpp"
|
||||
#include "osrm/exception.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/timezones.hpp"
|
||||
#include "util/version.hpp"
|
||||
@@ -187,9 +188,18 @@ int main(int argc, char *argv[]) try
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (const osrm::RuntimeError &e)
|
||||
{
|
||||
util::DumpSTXXLStats();
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << e.what();
|
||||
return e.GetCode();
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
util::Log(logERROR) << "[exception] " << e.what();
|
||||
util::DumpSTXXLStats();
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << e.what();
|
||||
util::Log(logERROR) << "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "customizer/customizer.hpp"
|
||||
|
||||
#include "osrm/exception.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/meminfo.hpp"
|
||||
#include "util/version.hpp"
|
||||
@@ -167,8 +168,15 @@ int main(int argc, char *argv[]) try
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
catch (const osrm::RuntimeError &e)
|
||||
{
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << e.what();
|
||||
return e.GetCode();
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << "[exception] " << e.what();
|
||||
util::Log(logERROR) << "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "osrm/exception.hpp"
|
||||
#include "osrm/extractor.hpp"
|
||||
#include "osrm/extractor_config.hpp"
|
||||
#include "util/log.hpp"
|
||||
@@ -168,8 +169,24 @@ int main(int argc, char *argv[]) try
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (const osrm::RuntimeError &e)
|
||||
{
|
||||
util::DumpSTXXLStats();
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << e.what();
|
||||
return e.GetCode();
|
||||
}
|
||||
catch (const std::system_error &e)
|
||||
{
|
||||
util::DumpSTXXLStats();
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << e.what();
|
||||
return e.code().value();
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
util::DumpSTXXLStats();
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << "[exception] " << e.what();
|
||||
util::Log(logERROR) << "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "partition/partition_config.hpp"
|
||||
#include "partition/partitioner.hpp"
|
||||
|
||||
#include "osrm/exception.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/meminfo.hpp"
|
||||
#include "util/timing_util.hpp"
|
||||
@@ -238,8 +239,16 @@ int main(int argc, char *argv[]) try
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
catch (const osrm::RuntimeError &e)
|
||||
{
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << e.what();
|
||||
return EXIT_FAILURE;
|
||||
return e.GetCode();
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << "[exception] " << e.what();
|
||||
util::Log(logERROR) << "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
|
||||
+10
-2
@@ -1,9 +1,11 @@
|
||||
#include "server/server.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/exception_utils.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/meminfo.hpp"
|
||||
#include "util/version.hpp"
|
||||
|
||||
#include "osrm/engine_config.hpp"
|
||||
#include "osrm/exception.hpp"
|
||||
#include "osrm/osrm.hpp"
|
||||
#include "osrm/storage_config.hpp"
|
||||
|
||||
@@ -57,7 +59,7 @@ EngineConfig::Algorithm stringToAlgorithm(const std::string &algorithm)
|
||||
return EngineConfig::Algorithm::CoreCH;
|
||||
if (algorithm == "MLD")
|
||||
return EngineConfig::Algorithm::MLD;
|
||||
throw util::exception("Invalid algorithm name: " + algorithm);
|
||||
throw util::RuntimeError(algorithm, ErrorCode::UnknownAlgorithm, SOURCE_REF);
|
||||
}
|
||||
|
||||
// generate boost::program_options object for the routing part
|
||||
@@ -331,8 +333,14 @@ int main(int argc, const char *argv[]) try
|
||||
routing_server.reset();
|
||||
util::Log() << "shutdown completed";
|
||||
}
|
||||
catch (const osrm::RuntimeError &e)
|
||||
{
|
||||
util::Log(logERROR) << e.what();
|
||||
return e.GetCode();
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logWARNING) << "[exception] " << e.what();
|
||||
util::Log(logWARNING) << "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
|
||||
+8
-1
@@ -1,8 +1,9 @@
|
||||
#include "storage/shared_memory.hpp"
|
||||
#include "storage/shared_monitor.hpp"
|
||||
#include "storage/storage.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "osrm/exception.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/meminfo.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
#include "util/version.hpp"
|
||||
|
||||
@@ -172,8 +173,14 @@ int main(const int argc, const char *argv[]) try
|
||||
|
||||
return storage.Run(max_wait);
|
||||
}
|
||||
catch (const osrm::RuntimeError &e)
|
||||
{
|
||||
util::Log(logERROR) << e.what();
|
||||
return e.GetCode();
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
util::DumpMemoryStats();
|
||||
util::Log(logERROR) << "[exception] " << e.what();
|
||||
util::Log(logERROR) << "Please provide more memory or disable locking the virtual "
|
||||
"address space (note: this makes OSRM swap, i.e. slow)";
|
||||
|
||||
@@ -17,5 +17,6 @@ namespace util
|
||||
{
|
||||
|
||||
void exception::anchor() const {}
|
||||
void RuntimeError::anchor() const {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user