Skip to content

Commit

Permalink
Error if the output file can't be opened. (#173)
Browse files Browse the repository at this point in the history
Verify output file can be created.
Trap errors in processor and exit accordingly.
  • Loading branch information
abellgithub authored Jul 13, 2024
1 parent 37b6cca commit 8bb990e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Untwine

Untwine is software from [Hobu, Inc.](https://hobu.co) for creating [Entwine Point Tile](https://entwine.io/entwine-point-tile.html) (EPT)
or [Cloud Optimized Point Cloud](https://copc.io/) (COPC) web services from [PDAL](https://pdal.io)-readable point cloud data sources. It
provides an alternative processing approach than the [Entwine](https://entwine.io)
software, but the output is expected to be compatible EPT/COPC.
Untwine is software from [Hobu, Inc.](https://hobu.co) for creating [Cloud Optimized Point Cloud](https://copc.io/) (COPC) web services from [PDAL](https://pdal.io)-readable point cloud data sources.


License
Expand Down Expand Up @@ -54,9 +51,9 @@ Options

Input files or directories containing input files. [Required]

- output_dir
- output_file

Output directory. [Required]
Output file. [Required]

- a_srs

Expand Down
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("Failure writing to file '" + 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 8bb990e

Please sign in to comment.