Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log error when "Export All" ES query fails #6976

Merged
merged 2 commits into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/plugins/kibana/public/settings/sections/objects/_objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,11 @@ uiModules.get('apps/settings')
retrieveAndExportDocs(objs);
};

$scope.exportAll = () => {
Promise.map($scope.services, (service) =>
service.service.scanAll('').then((results) =>
results.hits.map((hit) => _.extend(hit, {type: service.type}))
)
).then((results) => retrieveAndExportDocs(_.flattenDeep(results)));
};
$scope.exportAll = () => Promise.map($scope.services, service => service.service
.scanAll('')
.then(results => results.hits.map(hit => _.extend(hit, { type: service.type })))
.catch(error => notify.error(error))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually results in three different error blocks in the "more info" section of the error banner. I assume because there are three services or something, though I'm not familiar enough with this feature to say for certain. Perhaps the notify behavior should be moved to a .catch() on the .map() promise instead?

).then(results => retrieveAndExportDocs(_.flattenDeep(results)));

function retrieveAndExportDocs(objs) {
if (!objs.length) return notify.error('No saved objects to export.');
Expand Down
15 changes: 14 additions & 1 deletion src/ui/public/utils/__tests__/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,22 @@ describe('Scanner', function () {
scroll = sinon.stub(scanner.client, 'scroll', (req, cb) => cb(null, mockScroll));
});

it('should reject when an error occurs', function (done) {
search.restore();
search = sinon.stub(scanner.client, 'search', (req, cb) => cb(new Error('fail.')));
return scanner.scanAndMap('')
.then(function (response) {
done(new Error('should reject'));
})
.catch(function (error) {
expect(error.message).to.be('fail.');
done();
});
});

it('should search and then scroll for results', function () {
return scanner.scanAndMap('')
.then(function (error, response) {
.then(function (response) {
expect(search.called).to.be(true);
expect(scroll.called).to.be(true);
});
Expand Down
4 changes: 4 additions & 0 deletions src/ui/public/utils/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Scanner.prototype.scanAndMap = function (searchString, options, mapFn) {

return new Promise((resolve, reject) => {
const getMoreUntilDone = (error, response) => {
if (error) {
reject(error);
return;
}
const scanAllResults = opts.docCount === Infinity;
allResults.total = scanAllResults ? response.hits.total : Math.min(response.hits.total, opts.docCount);
scrollId = response._scroll_id || scrollId;
Expand Down