Skip to content

Commit cb2a362

Browse files
committed
Surround pipeline operations that throw with try-catch blocks
1 parent ce992de commit cb2a362

File tree

1 file changed

+85
-15
lines changed

1 file changed

+85
-15
lines changed

source/pdal/pdalc_pipeline.cpp

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,16 @@ namespace pdal
8585

8686
if (executor)
8787
{
88-
std::string s = executor->getPipeline();
89-
std::strncpy(buffer, s.c_str(), size - 1);
90-
result = std::min(s.length(), size);
88+
try
89+
{
90+
std::string s = executor->getPipeline();
91+
std::strncpy(buffer, s.c_str(), size - 1);
92+
result = std::min(s.length(), size);
93+
}
94+
catch (const std::exception &e)
95+
{
96+
printf("Found error while retrieving pipeline's string representation: %s\n", e.what());
97+
}
9198
}
9299

93100
}
@@ -108,10 +115,17 @@ namespace pdal
108115

109116
if (executor)
110117
{
111-
std::string s = executor->getMetadata();
112-
std::strncpy(metadata, s.c_str(), size);
113-
result = std::min(s.length(), size);
114-
}
118+
try
119+
{
120+
std::string s = executor->getMetadata();
121+
std::strncpy(metadata, s.c_str(), size);
122+
result = std::min(s.length(), size);
123+
}
124+
catch (const std::exception &e)
125+
{
126+
printf("Found error while retrieving pipeline's metadata: %s\n", e.what());
127+
}
128+
}
115129
}
116130

117131
return result;
@@ -130,9 +144,16 @@ namespace pdal
130144

131145
if (executor)
132146
{
133-
std::string s = executor->getSchema();
134-
std::strncpy(schema, s.c_str(), size);
135-
result = std::min(s.length(), size);
147+
try
148+
{
149+
std::string s = executor->getSchema();
150+
std::strncpy(schema, s.c_str(), size);
151+
result = std::min(s.length(), size);
152+
}
153+
catch (const std::exception &e)
154+
{
155+
printf("Found error while retrieving pipeline's schema: %s\n", e.what());
156+
}
136157
}
137158
}
138159

@@ -152,10 +173,17 @@ namespace pdal
152173

153174
if (executor)
154175
{
176+
try
177+
{
155178
std::string s = executor->getLog();
156179
std::strncpy(log, s.c_str(), size);
157180
result = std::min(s.length(), size);
158181
}
182+
catch (const std::exception &e)
183+
{
184+
printf("Found error while retrieving pipeline's log: %s\n", e.what());
185+
}
186+
}
159187
}
160188

161189
return result;
@@ -167,8 +195,15 @@ namespace pdal
167195

168196
if (ptr && ptr->get())
169197
{
198+
try
199+
{
170200
ptr->get()->setLogLevel(level);
171201
}
202+
catch (const std::exception &e)
203+
{
204+
printf("Found error while setting log level: %s\n", e.what());
205+
}
206+
}
172207
}
173208

174209
int PDALGetPipelineLogLevel(PDALPipelinePtr pipeline)
@@ -179,14 +214,42 @@ namespace pdal
179214

180215
int64_t PDALExecutePipeline(PDALPipelinePtr pipeline)
181216
{
217+
int64_t result = 0;
182218
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
183-
return (ptr && ptr->get()) ? ptr->get()->execute() : 0;
219+
220+
if (ptr && ptr->get())
221+
{
222+
try
223+
{
224+
result = ptr->get()->execute();
225+
}
226+
catch (const std::exception &e)
227+
{
228+
printf("Found error while executing pipeline: %s", e.what());
229+
}
230+
}
231+
232+
return result;
184233
}
185234

186235
bool PDALValidatePipeline(PDALPipelinePtr pipeline)
187236
{
237+
int64_t result = 0;
188238
Pipeline *ptr = reinterpret_cast<Pipeline *>(pipeline);
189-
return ptr && ptr->get() && ptr->get()->validate();
239+
240+
if (ptr && ptr->get())
241+
{
242+
try
243+
{
244+
result = ptr->get()->validate();
245+
}
246+
catch (const std::exception &e)
247+
{
248+
printf("Found error while validating pipeline: %s", e.what());
249+
}
250+
}
251+
252+
return result;
190253
}
191254

192255
PDALPointViewIteratorPtr PDALGetPointViews(PDALPipelinePtr pipeline)
@@ -196,11 +259,18 @@ namespace pdal
196259

197260
if (ptr && ptr->get())
198261
{
199-
auto &v = ptr->get()->getManagerConst().views();
262+
try
263+
{
264+
auto &v = ptr->get()->getManagerConst().views();
200265

201-
if (!v.empty())
266+
if (!v.empty())
267+
{
268+
views = new pdal::capi::PointViewIterator(v);
269+
}
270+
}
271+
catch (const std::exception &e)
202272
{
203-
views = new pdal::capi::PointViewIterator(v);
273+
printf("Found error while retrieving point views: %s\n", e.what());
204274
}
205275
}
206276

0 commit comments

Comments
 (0)