Skip to content

Commit

Permalink
Merge pull request #3043 from JasonRuonanWang/log
Browse files Browse the repository at this point in the history
use helper::Throw for all exceptions
  • Loading branch information
JasonRuonanWang authored Feb 6, 2022
2 parents 1cefd0c + 3e4676c commit 1e37438
Show file tree
Hide file tree
Showing 97 changed files with 2,062 additions and 1,450 deletions.
32 changes: 14 additions & 18 deletions source/adios2/core/ADIOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ ADIOS::ADIOS(const std::string configFile, helper::Comm comm,
{
if (!adios2sys::SystemTools::FileExists(configFile))
{
throw std::logic_error("Config file " + configFile +
" passed to ADIOS does not exist.");
helper::Throw<std::logic_error>("Core", "ADIOS", "ADIOS",
"config file " + configFile +
" not found");
}
if (helper::EndsWith(configFile, ".xml"))
{
Expand Down Expand Up @@ -103,11 +104,8 @@ IO &ADIOS::DeclareIO(const std::string name, const ArrayOrdering ArrayOrder)
}
else
{
throw std::invalid_argument(
"ERROR: IO with name " + name +
" previously declared with DeclareIO, name must be "
"unique,"
" in call to DeclareIO\n");
helper::Throw<std::invalid_argument>(
"Core", "ADIOS", "DeclareIO", "IO " + name + " declared twice");
}
}

Expand All @@ -126,17 +124,17 @@ IO &ADIOS::AtIO(const std::string name)

if (itIO == m_IOs.end())
{
throw std::invalid_argument("ERROR: IO with name " + name +
" was not declared, did you previously "
"call DeclareIO?, in call to AtIO\n");
helper::Throw<std::invalid_argument>("Core", "ADIOS", "AtIO",
"IO " + name +
" being used is not declared");
}
else
{
if (!itIO->second.IsDeclared())
{
throw std::invalid_argument("ERROR: IO with name " + name +
" was not declared, did you previously "
"call DeclareIO ?, in call to AtIO\n");
helper::Throw<std::invalid_argument>(
"Core", "ADIOS", "AtIO",
"IO " + name + " being used is not declared");
}
}

Expand Down Expand Up @@ -213,11 +211,9 @@ void ADIOS::CheckOperator(const std::string name) const
{
if (m_Operators.count(name) == 1)
{
throw std::invalid_argument(
"ERROR: Operator with name " + name +
", is already defined in either config file "
"or with call to DefineOperator, name must "
"be unique, in call to DefineOperator\n");
helper::Throw<std::invalid_argument>("Core", "ADIOS", "CheckOperator",
"Operator " + name +
" defined twice");
}
}

Expand Down
13 changes: 7 additions & 6 deletions source/adios2/core/Attribute.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Attribute.h"

#include "adios2/helper/adiosFunctions.h" //GetDataType<T>
#include "adios2/helper/adiosLog.h"
#include "adios2/helper/adiosType.h"

#include <cstring>
Expand Down Expand Up @@ -104,9 +105,9 @@ void Attribute<T>::Modify(const T *data, const size_t elements)
}
else
{
throw std::invalid_argument(
"ERROR: Trying to modify attribute " + this->m_Name +
" which has been defined as non-modifiable\n");
helper::Throw<std::invalid_argument>(
"Core", "Attribute", "Modify",
"Attribute " + this->m_Name + " being modified is not modifiable");
}
}

Expand All @@ -123,9 +124,9 @@ void Attribute<T>::Modify(const T &data)
}
else
{
throw std::invalid_argument(
"ERROR: Trying to modify attribute " + this->m_Name +
" which has been defined as non-modifiable\n");
helper::Throw<std::invalid_argument>(
"Core", "Attribute", "Modify",
"Attribute " + this->m_Name + " being modified is not modifiable");
}
}

Expand Down
11 changes: 6 additions & 5 deletions source/adios2/core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,19 @@ size_t Engine::DoSteps() const
// PRIVATE
void Engine::ThrowUp(const std::string function) const
{
throw std::invalid_argument("ERROR: Engine derived class " + m_EngineType +
" doesn't implement function " + function +
"\n");
helper::Throw<std::invalid_argument>("Core", "Engine", "ThrowUp",
"Engine " + m_EngineType +
" does not support " + function);
}

void Engine::CheckOpenModes(const std::set<Mode> &modes,
const std::string hint) const
{
if (modes.count(m_OpenMode) == 0)
{
throw std::invalid_argument(
"ERROR: Engine Open Mode not valid for function, " + hint);
helper::Throw<std::invalid_argument>("Core", "Engine", "CheckOpenModes",
"Engine open mode not valid for " +
hint);
}
}

Expand Down
46 changes: 24 additions & 22 deletions source/adios2/core/Engine.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ typename Variable<T>::Span &Engine::Put(Variable<T> &variable,
", in call to Variable<T>::Span Put");
if (!variable.m_Operations.empty())
{
throw std::invalid_argument(
"ERROR: span currently not supported with "
"operations, remove calls to Variable<T>::AddOperation or use "
"Variable<T>::RemoveOperations, in call to Variable<T>::Span "
"Engine::Put");
helper::Throw<std::invalid_argument>(
"Core", "Engine", "Put",
"Span does not support Operations. Try removing Operations from "
"variables using Span");
}

auto itSpan = variable.m_BlocksSpan.emplace(
Expand All @@ -60,10 +59,10 @@ void Engine::Put(Variable<T> &variable, const T *data, const Mode launch)
DoPutSync(variable, data);
break;
default:
throw std::invalid_argument(
"ERROR: invalid launch Mode for variable " + variable.m_Name +
", only Mode::Deferred and Mode::Sync are valid, in call to "
"Put\n");
helper::Throw<std::invalid_argument>(
"Core", "Engine", "Put",
"invalid launch Mode for variable " + variable.m_Name +
", only Mode::Deferred and Mode::Sync are valid");
}
}

Expand Down Expand Up @@ -106,10 +105,10 @@ void Engine::Get(Variable<T> &variable, T *data, const Mode launch)
DoGetSync(variable, data);
break;
default:
throw std::invalid_argument(
"ERROR: invalid launch Mode for variable " + variable.m_Name +
", only Mode::Deferred and Mode::Sync are valid, in call to "
"Get\n");
helper::Throw<std::invalid_argument>(
"Core", "Engine", "Get",
"invalid launch Mode for variable " + variable.m_Name +
", only Mode::Deferred and Mode::Sync are valid");
}
}

Expand Down Expand Up @@ -151,8 +150,10 @@ void Engine::Get(core::Variable<T> &variable, T **data) const
}
else
{
throw std::runtime_error("Currently, only the inline engine implements "
"Get(core::Variable<T>&, T**)");
helper::Throw<std::runtime_error>(
"Core", "Engine", "Get",
"Engine " + m_EngineType +
" does not support Get(core::Variable<T>&, T**)");
}
}

Expand All @@ -179,10 +180,10 @@ typename Variable<T>::BPInfo *Engine::Get(Variable<T> &variable,
info = DoGetBlockSync(variable);
break;
default:
throw std::invalid_argument(
"ERROR: invalid launch Mode for variable " + variable.m_Name +
", only Mode::Deferred and Mode::Sync are valid, in call to "
"GetBlock\n");
helper::Throw<std::invalid_argument>(
"Core", "Engine", "Get",
"invalid launch Mode for variable " + variable.m_Name +
", only Mode::Deferred and Mode::Sync are valid");
}

CommonChecks<T>(variable, info->Data, {{Mode::Read}}, "in call to Get");
Expand Down Expand Up @@ -254,9 +255,10 @@ Variable<T> &Engine::FindVariable(const std::string &variableName,
Variable<T> *variable = m_IO.InquireVariable<T>(variableName);
if (variable == nullptr)
{
throw std::invalid_argument("ERROR: variable " + variableName +
" not found in IO " + m_IO.m_Name + ", " +
hint + "\n");
helper::Throw<std::invalid_argument>("Core", "Engine", "FindVariable",
"variable " + variableName +
" not found in IO " +
m_IO.m_Name + ", " + hint);
}
return *variable;
}
Expand Down
71 changes: 36 additions & 35 deletions source/adios2/core/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ struct ThrowError
std::shared_ptr<Engine> operator()(IO &, const std::string &, const Mode,
helper::Comm) const
{
throw std::invalid_argument(Err);
helper::Throw<std::invalid_argument>("Core", "IO", "Operator", Err);
return nullptr;
}
std::string Err;
};
Expand Down Expand Up @@ -274,9 +275,10 @@ size_t IO::AddTransport(const std::string type, const Params &parameters)
if (parameters.count("transport") == 1 ||
parameters.count("Transport") == 1)
{
throw std::invalid_argument("ERROR: key Transport (or transport) "
"is not valid for transport type " +
type + ", in call to AddTransport)");
helper::Throw<std::invalid_argument>(
"Core", "IO", "AddTransport",
"key Transport (or transport) is not allowed in transport "
"parameters");
}

CheckTransportType(type);
Expand All @@ -292,10 +294,10 @@ void IO::SetTransportParameter(const size_t transportIndex,
PERFSTUBS_SCOPED_TIMER("IO::other");
if (transportIndex >= m_TransportsParameters.size())
{
throw std::invalid_argument(
"ERROR: transportIndex is larger than "
"transports created with AddTransport, for key: " +
key + ", value: " + value + "in call to SetTransportParameter\n");
helper::Throw<std::invalid_argument>(
"Core", "IO", "SetTransportParameter",
"transport Index " + std::to_string(transportIndex) +
" does not exist");
}

m_TransportsParameters[transportIndex][key] = value;
Expand Down Expand Up @@ -520,9 +522,8 @@ Engine &IO::Open(const std::string &name, const Mode mode, helper::Comm comm)
{
if (isEngineActive) // check if active
{
throw std::invalid_argument("ERROR: IO Engine with name " + name +
" already created and is active (Close "
"not called yet), in call to Open.\n");
helper::Throw<std::invalid_argument>(
"Core", "IO", "Open", "Engine " + name + " is opened twice");
}
}

Expand Down Expand Up @@ -619,15 +620,17 @@ Engine &IO::Open(const std::string &name, const Mode mode, helper::Comm comm)
{
if (mode_to_use == Mode::Append)
{
throw std::runtime_error(
"Append mode is not supported for the inline engine.");
helper::Throw<std::runtime_error>(
"Core", "IO", "Open",
"Append mode is not supported in the inline engine.");
}

// See inline.rst:44
if (mode_to_use == Mode::Sync)
{
throw std::runtime_error(
"Sync mode is not supported for the inline engine.");
helper::Throw<std::runtime_error>(
"Core", "IO", "Open",
"Sync mode is not supported in the inline engine.");
}

if (m_Engines.size() >= 2)
Expand All @@ -638,7 +641,7 @@ Engine &IO::Open(const std::string &name, const Mode mode, helper::Comm comm)
"reader. ";
msg += "There are already two engines declared, so no more can be "
"added.";
throw std::runtime_error(msg);
helper::Throw<std::runtime_error>("Core", "IO", "Open", msg);
}
// Now protect against declaration of two writers, or declaration of
// two readers:
Expand All @@ -653,7 +656,7 @@ Engine &IO::Open(const std::string &name, const Mode mode, helper::Comm comm)
". ";
msg += "The inline engine requires exactly one writer and one "
"reader.";
throw std::runtime_error(msg);
helper::Throw<std::runtime_error>("Core", "IO", "Open", msg);
}
}
}
Expand All @@ -675,19 +678,17 @@ Engine &IO::Open(const std::string &name, const Mode mode, helper::Comm comm)
}
else
{
throw std::invalid_argument("ERROR: engine " + m_EngineType +
" not supported, IO SetEngine must add "
"a supported engine, in call to "
"Open\n");
helper::Throw<std::invalid_argument>("Core", "IO", "Open",
"Engine type " + m_EngineType +
" is not valid");
}

auto itEngine = m_Engines.emplace(name, std::move(engine));

if (!itEngine.second)
{
throw std::invalid_argument("ERROR: engine of type " + m_EngineType +
" and name " + name +
" could not be created, in call to Open\n");
helper::Throw<std::invalid_argument>(
"Core", "IO", "Open", "failed to create Engine " + m_EngineType);
}
// return a reference
return *itEngine.first->second.get();
Expand All @@ -709,9 +710,8 @@ Engine &IO::GetEngine(const std::string &name)
auto itEngine = m_Engines.find(name);
if (itEngine == m_Engines.end())
{
throw std::invalid_argument(
"ERROR: engine name " + name +
" could not be found, in call to GetEngine\n");
helper::Throw<std::invalid_argument>("Core", "IO", "GetEngine",
"Engine " + name + " not found");
}
// return a reference
return *itEngine->second.get();
Expand Down Expand Up @@ -830,21 +830,22 @@ void IO::CheckAttributeCommon(const std::string &name) const
auto itAttribute = m_Attributes.find(name);
if (itAttribute != m_Attributes.end())
{
throw std::invalid_argument("ERROR: attribute " + name +
" exists in IO object " + m_Name +
", in call to DefineAttribute\n");
helper::Throw<std::invalid_argument>(
"Core", "IO", "CheckAttributeCommon",
"Attribute " + name + " exists in IO " + m_Name +
", in call to DefineAttribute");
}
}

void IO::CheckTransportType(const std::string type) const
{
if (type.empty() || type.find("=") != type.npos)
{
throw std::invalid_argument(
"ERROR: wrong first argument " + type +
", must "
"be a single word for a supported transport type, in "
"call to IO AddTransport \n");
helper::Throw<std::invalid_argument>(
"Core", "IO", "CheckTransportType",
"wrong first argument " + type +
", must be a single word for a supported transport type, in "
"call to IO AddTransport");
}
}

Expand Down
Loading

0 comments on commit 1e37438

Please sign in to comment.