[core] Rationalize error handling for resource loading

* Standardize on std::exception_ptr as the error representation
  (fixes #2854).
* Don't format textual strings at the error source; pass on the
  constituent data via observer method parameters instead.
* Use the null object pattern to simplify observer notification code.
* Further refactoring for ResourceLoading tests.
This commit is contained in:
John Firebaugh
2015-12-22 15:10:24 -08:00
parent 7bd4745cf1
commit 16de579d7c
28 changed files with 405 additions and 472 deletions

View File

@@ -6,8 +6,6 @@
#include <mbgl/style/style.hpp>
#include <mbgl/storage/file_source.hpp>
#include <sstream>
namespace mbgl {
VectorTileData::VectorTileData(const TileID& id_,
@@ -32,14 +30,10 @@ VectorTileData::VectorTileData(const TileID& id_,
Seconds modified_,
Seconds expires_) {
if (err) {
try {
std::rethrow_exception(err);
} catch (const std::exception& e) {
error = e.what();
state = State::obsolete;
callback();
return;
}
error = err;
state = State::obsolete;
callback();
return;
}
if (!tile) {
@@ -86,9 +80,7 @@ VectorTileData::VectorTileData(const TileID& id_,
redoPlacement();
}
} else {
std::stringstream message;
message << "Failed to parse [" << std::string(id) << "]: " << result.get<std::string>();
error = message.str();
error = result.get<std::exception_ptr>();
state = State::obsolete;
}
@@ -130,9 +122,7 @@ bool VectorTileData::parsePending(std::function<void()> callback) {
redoPlacement();
}
} else {
std::stringstream message;
message << "Failed to parse [" << std::string(id) << "]: " << result.get<std::string>();
error = message.str();
error = result.get<std::exception_ptr>();
state = State::obsolete;
}