Skip to content

Commit

Permalink
Added error handling and reporting for paged databases when protocol …
Browse files Browse the repository at this point in the history
…or file has not been found.
  • Loading branch information
robertosfield committed Oct 14, 2024
1 parent 2efa0f8 commit e0604b9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/vsg/io/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ vsg::ref_ptr<vsg::Object> tile::read(const vsg::Path& filename, vsg::ref_ptr<con
auto extension = vsg::lowerCaseFileExtension(filename);
if (extension != ".tile") return {};

if (!options) return {};

auto tile_info = filename.substr(0, filename.length() - 5);
if (tile_info == "root")
{
Expand Down Expand Up @@ -179,6 +181,32 @@ vsg::ref_ptr<vsg::Object> tile::read_root(vsg::ref_ptr<const vsg::Options> optio
}
}

// error handling.
if (group->children.empty())
{
// check to see if we required a protocol like http
const auto& filename = settings->imageLayer;
auto pos = filename.find("://");
if (pos != vsg::Path::npos)
{
auto protocol = filename.substr(0, pos);

Features features;
if (vsg::getFeatures(options, features))
{
if (auto itr = features.protocolFeatureMap.find(protocol); itr != features.protocolFeatureMap.end())
{
return ReadError::create("vsg::tile::read_root(..) could not data.");
}
}
return ReadError::create("vsg::tile::read_root(..) no support available for protocol.");
}
else
{
return ReadError::create("vsg::tile::read_root(..) unable to load file.");
}
}

uint64_t maxLevel = 20;
uint64_t estimatedNumOfTilesBelow = 0;
uint64_t maxNumTilesBelow = 1024;
Expand Down
10 changes: 9 additions & 1 deletion src/vsg/nodes/TileDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,15 @@ bool TileDatabase::readDatabase(vsg::ref_ptr<const vsg::Options> options)
auto local_options = options ? vsg::Options::create(*options) : vsg::Options::create();
local_options->readerWriters.insert(local_options->readerWriters.begin(), tileReader);

child = vsg::read_cast<vsg::Node>("root.tile", local_options);
auto result = vsg::read("root.tile", local_options);

child = result.cast<vsg::Node>();
if (!child)
{
auto error = result.cast<ReadError>();
if (error) warn("TileDatabase::readDatabase() imageLayer = ", settings->imageLayer, " failed to load. Error: ", error->message);
else warn("TileDatabase::readDatabase() imageLayer = ", settings->imageLayer, " failed to load.");
}

return child.valid();
}
Expand Down

0 comments on commit e0604b9

Please sign in to comment.