Skip to content

Commit

Permalink
Verify output file can be created.
Browse files Browse the repository at this point in the history
Trap errors in processor and exit accordingly.
  • Loading branch information
abellgithub committed Jul 12, 2024
1 parent 37b6cca commit e3b9f0e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 1 addition & 3 deletions bu/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ void Processor::run()
}
catch (const std::exception& ex)
{
std::cerr << "Exception: " << ex.what() << "\n";
m_manager.queueWithError(m_vi.octant(), ex.what());
return;
}
catch (...)
{
std::string msg = std::string("Unexpected error processing ") + m_vi.key().toString() + ".";
std::cerr << "Exception: " << msg << "\n";
m_manager.queueWithError(m_vi.octant(), msg);
return;
}
Expand Down Expand Up @@ -490,7 +488,7 @@ void Processor::createChunk(const VoxelKey& key, pdal::PointViewPtr view)
out.write(reinterpret_cast<const char *>(chunk.data()), chunk.size());
out.close();
if (!out)
throw FatalError("Failure writing to '" + m_b.opts.outputName + "'.");
throw FatalError("Failure writing to file '" + m_b.opts.outputName + "'.");
}

void Processor::fillPointBuf(pdal::PointRef& point, std::vector<char>& buf,
Expand Down
3 changes: 2 additions & 1 deletion bu/PyramidManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void PyramidManager::run()

if (m_error.size())
{
std::cerr << "Exception: " << m_error << "\n";
lock.unlock();
m_pool.join();
throw FatalError(m_error);
}
}
Expand Down
2 changes: 1 addition & 1 deletion epf/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void Writer::run()
std::lock_guard<std::mutex> lock(m_mutex);
if (!out)
{
m_pool.setError("Failure writing to '" + path(wd.key) + "'.");
m_pool.setError("EPF Failure writing to '" + path(wd.key) + "'.");
m_stop = true;
}
else
Expand Down
10 changes: 9 additions & 1 deletion untwine/Untwine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,22 @@ bool handleOptions(pdal::StringList& arglist, Options& options)
std::cout << "untwine version (" << UNTWINE_VERSION << ")\n";
if (help)
{
std::cout << "Usage: untwine [output file/directory] <options>\n";
std::cout << "Usage: untwine output file <options>\n";
programArgs.dump(std::cout, 2, 80);
}
if (help || version)
return false;

programArgs.parse(arglist);

// Make sure the output file can be opened so that we can provide an early error if
// there's a problem.
std::ofstream tmp(os::toNative(options.outputName), std::ios::out | std::ios::binary);
if (!tmp)
throw FatalError("Can't open file '" + options.outputName + "' for output");
tmp.close();
pdal::FileUtils::deleteFile(options.outputName);

if (!tempArg->set())
{
options.tempDir = options.outputName + "_tmp";
Expand Down

0 comments on commit e3b9f0e

Please sign in to comment.