Skip to content

Commit 351d751

Browse files
Unify exception types (#1355)
* Remove ParseError Leftover from lenient parsing PR, unused. * Swallow unsupported_data_error into OperationUnsupportedInBackend * Rename no_such_attribute_error -> error::NoSuchAttribute
1 parent 9a22cd2 commit 351d751

File tree

8 files changed

+69
-63
lines changed

8 files changed

+69
-63
lines changed

include/openPMD/Error.hpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,10 @@ namespace error
107107
std::string description_in);
108108
};
109109

110-
/*
111-
* Inrecoverable parse error from the frontend.
112-
*/
113-
class ParseError : public Error
110+
class NoSuchAttribute : public Error
114111
{
115112
public:
116-
ParseError(std::string what);
113+
NoSuchAttribute(std::string attributeName);
117114
};
118115
} // namespace error
119116

@@ -122,4 +119,16 @@ namespace error
122119
*
123120
*/
124121
using no_such_file_error = error::ReadError;
122+
123+
/**
124+
* @brief Backward-compatibility alias for unsupported_data_error.
125+
*
126+
*/
127+
using unsupported_data_error = error::OperationUnsupportedInBackend;
128+
129+
/**
130+
* @brief Backward-compatibility alias for no_such_attribute_error.
131+
*
132+
*/
133+
using no_such_attribute_error = error::NoSuchAttribute;
125134
} // namespace openPMD

include/openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#pragma once
2222

2323
#include "openPMD/IO/ADIOS/ADIOS1FilePosition.hpp"
24+
#include "openPMD/ThrowError.hpp"
2425
#include "openPMD/auxiliary/StringManip.hpp"
2526
#include "openPMD/backend/Attribute.hpp"
2627
#include "openPMD/backend/Writable.hpp"
@@ -102,8 +103,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
102103
else if (sizeof(long) == 8u)
103104
return adios_long;
104105
else
105-
throw unsupported_data_error(
106-
"No native equivalent for Datatype::SHORT found.");
106+
error::throwOperationUnsupportedInBackend(
107+
"ADIOS1", "No native equivalent for Datatype::SHORT found.");
107108
case DT::INT:
108109
case DT::VEC_INT:
109110
if (sizeof(int) == 2u)
@@ -113,8 +114,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
113114
else if (sizeof(int) == 8u)
114115
return adios_long;
115116
else
116-
throw unsupported_data_error(
117-
"No native equivalent for Datatype::INT found.");
117+
error::throwOperationUnsupportedInBackend(
118+
"ADIOS1", "No native equivalent for Datatype::INT found.");
118119
case DT::LONG:
119120
case DT::VEC_LONG:
120121
if (sizeof(long) == 2u)
@@ -124,8 +125,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
124125
else if (sizeof(long) == 8u)
125126
return adios_long;
126127
else
127-
throw unsupported_data_error(
128-
"No native equivalent for Datatype::LONG found.");
128+
error::throwOperationUnsupportedInBackend(
129+
"ADIOS1", "No native equivalent for Datatype::LONG found.");
129130
case DT::LONGLONG:
130131
case DT::VEC_LONGLONG:
131132
if (sizeof(long long) == 2u)
@@ -135,8 +136,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
135136
else if (sizeof(long long) == 8u)
136137
return adios_long;
137138
else
138-
throw unsupported_data_error(
139-
"No native equivalent for Datatype::LONGLONG found.");
139+
error::throwOperationUnsupportedInBackend(
140+
"ADIOS1", "No native equivalent for Datatype::LONGLONG found.");
140141
case DT::USHORT:
141142
case DT::VEC_USHORT:
142143
if (sizeof(unsigned short) == 2u)
@@ -146,8 +147,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
146147
else if (sizeof(unsigned long) == 8u)
147148
return adios_unsigned_long;
148149
else
149-
throw unsupported_data_error(
150-
"No native equivalent for Datatype::USHORT found.");
150+
error::throwOperationUnsupportedInBackend(
151+
"ADIOS1", "No native equivalent for Datatype::USHORT found.");
151152
case DT::UINT:
152153
case DT::VEC_UINT:
153154
if (sizeof(unsigned int) == 2u)
@@ -157,8 +158,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
157158
else if (sizeof(unsigned int) == 8u)
158159
return adios_unsigned_long;
159160
else
160-
throw unsupported_data_error(
161-
"No native equivalent for Datatype::UINT found.");
161+
error::throwOperationUnsupportedInBackend(
162+
"ADIOS1", "No native equivalent for Datatype::UINT found.");
162163
case DT::ULONG:
163164
case DT::VEC_ULONG:
164165
if (sizeof(unsigned long) == 2u)
@@ -168,8 +169,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
168169
else if (sizeof(unsigned long) == 8u)
169170
return adios_unsigned_long;
170171
else
171-
throw unsupported_data_error(
172-
"No native equivalent for Datatype::ULONG found.");
172+
error::throwOperationUnsupportedInBackend(
173+
"ADIOS1", "No native equivalent for Datatype::ULONG found.");
173174
case DT::ULONGLONG:
174175
case DT::VEC_ULONGLONG:
175176
if (sizeof(unsigned long long) == 2u)
@@ -179,7 +180,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
179180
else if (sizeof(unsigned long long) == 8u)
180181
return adios_unsigned_long;
181182
else
182-
throw unsupported_data_error(
183+
error::throwOperationUnsupportedInBackend(
184+
"ADIOS1",
183185
"No native equivalent for Datatype::ULONGLONG found.");
184186
case DT::FLOAT:
185187
case DT::VEC_FLOAT:
@@ -199,8 +201,8 @@ inline ADIOS_DATATYPES getBP1DataType(Datatype dtype)
199201
return adios_double_complex;
200202
case DT::CLONG_DOUBLE:
201203
case DT::VEC_CLONG_DOUBLE:
202-
throw unsupported_data_error(
203-
"No native equivalent for Datatype::CLONG_DOUBLE found.");
204+
error::throwOperationUnsupportedInBackend(
205+
"ADIOS1", "No native equivalent for Datatype::CLONG_DOUBLE found.");
204206
case DT::STRING:
205207
return adios_string;
206208
case DT::VEC_STRING:

include/openPMD/IO/AbstractIOHandler.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@
3838

3939
namespace openPMD
4040
{
41-
42-
class unsupported_data_error : public std::runtime_error
43-
{
44-
public:
45-
unsupported_data_error(std::string const &what_arg)
46-
: std::runtime_error(what_arg)
47-
{}
48-
virtual ~unsupported_data_error()
49-
{}
50-
};
51-
5241
/**
5342
* @brief Determine what items should be flushed upon Series::flush()
5443
*

include/openPMD/ThrowError.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,7 @@ throwOperationUnsupportedInBackend(std::string backend, std::string what);
6767
Reason reason_in,
6868
std::optional<std::string> backend,
6969
std::string description_in);
70+
71+
[[noreturn]] OPENPMDAPI_EXPORT void
72+
throwNoSuchAttribute(std::string attributeName);
7073
} // namespace openPMD::error

include/openPMD/backend/Attributable.hpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#pragma once
2222

2323
#include "openPMD/IO/AbstractIOHandler.hpp"
24+
#include "openPMD/ThrowError.hpp"
2425
#include "openPMD/auxiliary/OutOfRangeMsg.hpp"
2526
#include "openPMD/backend/Attribute.hpp"
2627
#include "openPMD/backend/Writable.hpp"
@@ -50,16 +51,6 @@ class Attributable;
5051
class Iteration;
5152
class Series;
5253

53-
class no_such_attribute_error : public std::runtime_error
54-
{
55-
public:
56-
no_such_attribute_error(std::string const &what_arg)
57-
: std::runtime_error(what_arg)
58-
{}
59-
virtual ~no_such_attribute_error()
60-
{}
61-
};
62-
6354
namespace internal
6455
{
6556
class AttributableData
@@ -475,7 +466,7 @@ inline bool Attributable::setAttributeImpl(
475466
{
476467
auxiliary::OutOfRangeMsg const out_of_range_msg(
477468
"Attribute", "can not be set (read-only).");
478-
throw no_such_attribute_error(out_of_range_msg(key));
469+
error::throwNoSuchAttribute(out_of_range_msg(key));
479470
}
480471

481472
dirty() = true;

src/Error.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ namespace error
133133
affectedObject, reason, std::move(backend), std::move(description));
134134
}
135135

136-
ParseError::ParseError(std::string what) : Error("Parse Error: " + what)
136+
NoSuchAttribute::NoSuchAttribute(std::string attributeName)
137+
: Error(std::move(attributeName))
137138
{}
139+
140+
void throwNoSuchAttribute(std::string attributeName)
141+
{
142+
throw NoSuchAttribute(std::move(attributeName));
143+
}
138144
} // namespace error
139145
} // namespace openPMD

src/IO/ADIOS/CommonADIOS1IOHandler.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,9 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::openDataset(
882882
else if (sizeof(long long) == 2u)
883883
dtype = DT::LONGLONG;
884884
else
885-
throw unsupported_data_error(
886-
"[ADIOS1] No native equivalent for Datatype adios_short "
887-
"found.");
885+
error::throwOperationUnsupportedInBackend(
886+
"ADIOS1",
887+
"No native equivalent for Datatype adios_short found.");
888888
break;
889889
case adios_integer:
890890
if (sizeof(short) == 4u)
@@ -896,9 +896,9 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::openDataset(
896896
else if (sizeof(long long) == 4u)
897897
dtype = DT::LONGLONG;
898898
else
899-
throw unsupported_data_error(
900-
"[ADIOS1] No native equivalent for Datatype adios_integer "
901-
"found.");
899+
error::throwOperationUnsupportedInBackend(
900+
"ADIOS1",
901+
"No native equivalent for Datatype adios_integer found.");
902902
break;
903903
case adios_long:
904904
if (sizeof(short) == 8u)
@@ -910,8 +910,9 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::openDataset(
910910
else if (sizeof(long long) == 8u)
911911
dtype = DT::LONGLONG;
912912
else
913-
throw unsupported_data_error(
914-
"[ADIOS1] No native equivalent for Datatype adios_long found.");
913+
error::throwOperationUnsupportedInBackend(
914+
"ADIOS1",
915+
"No native equivalent for Datatype adios_long found.");
915916
break;
916917
case adios_unsigned_byte:
917918
dtype = DT::UCHAR;
@@ -926,9 +927,10 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::openDataset(
926927
else if (sizeof(unsigned long long) == 2u)
927928
dtype = DT::ULONGLONG;
928929
else
929-
throw unsupported_data_error(
930-
"[ADIOS1] No native equivalent for Datatype "
931-
"adios_unsigned_short found.");
930+
error::throwOperationUnsupportedInBackend(
931+
"ADIOS1",
932+
"No native equivalent for Datatype adios_unsigned_short "
933+
"found.");
932934
break;
933935
case adios_unsigned_integer:
934936
if (sizeof(unsigned short) == 4u)
@@ -940,9 +942,10 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::openDataset(
940942
else if (sizeof(unsigned long long) == 4u)
941943
dtype = DT::ULONGLONG;
942944
else
943-
throw unsupported_data_error(
944-
"[ADIOS1] No native equivalent for Datatype "
945-
"adios_unsigned_integer found.");
945+
error::throwOperationUnsupportedInBackend(
946+
"ADIOS1",
947+
"No native equivalent for Datatype adios_unsigned_integer "
948+
"found.");
946949
break;
947950
case adios_unsigned_long:
948951
if (sizeof(unsigned short) == 8u)
@@ -954,9 +957,9 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::openDataset(
954957
else if (sizeof(unsigned long long) == 8u)
955958
dtype = DT::ULONGLONG;
956959
else
957-
throw unsupported_data_error(
958-
"[ADIOS1] No native equivalent for Datatype "
959-
"adios_unsigned_long found.");
960+
error::throwOperationUnsupportedInBackend(
961+
"ADIOS1",
962+
"No native equivalent for Datatype adios_unsigned_long found.");
960963
break;
961964
case adios_real:
962965
dtype = DT::FLOAT;
@@ -977,7 +980,8 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::openDataset(
977980
case adios_string:
978981
case adios_string_array:
979982
default:
980-
throw unsupported_data_error(
983+
error::throwOperationUnsupportedInBackend(
984+
"ADIOS1",
981985
"[ADIOS1] Datatype not implemented for ADIOS dataset writing");
982986
}
983987
*parameters.dtype = dtype;

src/binding/python/Error.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ void init_Error(py::module &m)
1515
py::register_exception<error::BackendConfigSchema>(
1616
m, "ErrorBackendConfigSchema", baseError);
1717
py::register_exception<error::Internal>(m, "ErrorInternal", baseError);
18+
py::register_exception<error::NoSuchAttribute>(
19+
m, "ErrorNoSuchAttribute", baseError);
1820

1921
#ifndef NDEBUG
2022
m.def("test_throw", [](std::string description) {

0 commit comments

Comments
 (0)