Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[node] Reset Style::Impl::lastError when loading a new style
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jul 24, 2017
1 parent 264ca96 commit a178248
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
51 changes: 51 additions & 0 deletions platform/node/test/js/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,54 @@ test(`render ignores request functions calling the callback a second time`, func
});
});

test(`render reports an error from loading the current style`, function(t) {
var map = new mbgl.Map({
request: function(req, callback) {
var data = mockfs.dataForRequest(req);
if (mockfs.source_vector === data) {
callback(new Error('message'));
} else {
callback(null, { data: data });
}
}
});
map.load(mockfs.style_vector);
map.render({ zoom: 16 }, function(err, pixels) {
t.assert(err);
t.assert(/message/.test(err.message));
t.assert(!pixels);

map.render({ zoom: 16 }, function(err, pixels) {
t.assert(err);
t.assert(/message/.test(err.message));
t.assert(!pixels);
t.end();
});
});
});

test(`render does not report an error from rendering a previous style`, function(t) {
var map = new mbgl.Map({
request: function(req, callback) {
var data = mockfs.dataForRequest(req);
if (mockfs.source_vector === data) {
callback(new Error('message'));
} else {
callback(null, { data: data });
}
}
});
map.load(mockfs.style_vector);
map.render({ zoom: 16 }, function(err, pixels) {
t.assert(err);
t.assert(/message/.test(err.message));
t.assert(!pixels);

map.load(mockfs.style_raster);
map.render({ zoom: 16 }, function(err, pixels) {
t.error(err);
t.assert(pixels);
t.end();
});
});
});
2 changes: 2 additions & 0 deletions src/mbgl/style/style_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ Style::Impl::Impl(Scheduler& scheduler_, FileSource& fileSource_, float pixelRat
Style::Impl::~Impl() = default;

void Style::Impl::loadJSON(const std::string& json_) {
lastError = nullptr;
observer->onStyleLoading();

url.clear();
parse(json_);
}

void Style::Impl::loadURL(const std::string& url_) {
lastError = nullptr;
observer->onStyleLoading();

loaded = false;
Expand Down

0 comments on commit a178248

Please sign in to comment.