1
0
Fork 0

Merge branch 'devel' of https://github.com/arangodb/arangodb into devel

* 'devel' of https://github.com/arangodb/arangodb:
  Lint
  No more need to wrap legacy errors in new Foxx HTTP API
  fixed initializing bug in dashboard ui at initial startup
  Correctly expose errors in old Foxx API
  Fix error expecations
This commit is contained in:
Jan Christoph Uhde 2017-05-17 13:49:45 +02:00
commit 55175386e7
6 changed files with 61 additions and 82 deletions

View File

@ -32,6 +32,7 @@ const actions = require('@arangodb/actions');
const FoxxManager = require('@arangodb/foxx/manager'); const FoxxManager = require('@arangodb/foxx/manager');
const request = require('@arangodb/request'); const request = require('@arangodb/request');
const db = require('@arangodb').db; const db = require('@arangodb').db;
const ArangoError = require('@arangodb').ArangoError;
const joinPath = require('path').join; const joinPath = require('path').join;
const fs = require('fs'); const fs = require('fs');
const fmu = require('@arangodb/foxx/manager-utils'); const fmu = require('@arangodb/foxx/manager-utils');
@ -54,6 +55,9 @@ function proxyLocal (method, url, qs, body, headers = {}) {
headers['content-length'] = body.length; headers['content-length'] = body.length;
} }
const res = request({method, url, qs, headers, body}); const res = request({method, url, qs, headers, body});
if (res.json && res.json.errorNum) {
throw new ArangoError(res.json);
}
res.throw(); res.throw();
return res.body ? JSON.parse(res.body) : null; return res.body ? JSON.parse(res.body) : null;
} }

View File

@ -846,7 +846,15 @@
} }
var currentP = fmtNumber(self.history[self.server].residentSizePercent * 100, 2); var currentP = fmtNumber(self.history[self.server].residentSizePercent * 100, 2);
var data = [prettyBytes(self.history[self.server].physicalMemory)]; var data;
if (self.history[self.server].physicalMemory) {
this.removeEmptyDataLabels();
data = [prettyBytes(self.history[self.server].physicalMemory)];
} else {
this.addEmptyDataLabels();
return;
}
if (self.history[self.server].residentSizeChart === undefined) { if (self.history[self.server].residentSizeChart === undefined) {
this.addEmptyDataLabels(); this.addEmptyDataLabels();
@ -966,7 +974,8 @@
if (self.history[self.server].residentSizeChart === undefined) { if (self.history[self.server].residentSizeChart === undefined) {
self.addEmptyDataLabels(); self.addEmptyDataLabels();
return; // initialize with 0 values then
// return;
} else { } else {
self.removeEmptyDataLabels(); self.removeEmptyDataLabels();
} }
@ -1041,9 +1050,15 @@
return fmtNumber(((d * 100 * 100) / 100), 0) + '%'; return fmtNumber(((d * 100 * 100) / 100), 0) + '%';
}); });
if (self.history[self.server][k]) {
d3.select(selector) d3.select(selector)
.datum(self.history[self.server][k]) .datum(self.history[self.server][k])
.call(self.distributionCharts[k]); .call(self.distributionCharts[k]);
} else {
d3.select(selector)
.datum([])
.call(self.distributionCharts[k]);
}
nv.utils.windowResize(self.distributionCharts[k].update); nv.utils.windowResize(self.distributionCharts[k].update);
@ -1065,9 +1080,15 @@
self.distributionCharts[k].height(dimensions.height); self.distributionCharts[k].height(dimensions.height);
// update data // update data
if (self.history[self.server][k]) {
d3.select(selector) d3.select(selector)
.datum(self.history[self.server][k]) .datum(self.history[self.server][k])
.call(self.distributionCharts[k]); .call(self.distributionCharts[k]);
} else {
d3.select(selector)
.datum([])
.call(self.distributionCharts[k]);
}
// trigger resize // trigger resize
nv.utils.windowResize(self.distributionCharts[k].update); nv.utils.windowResize(self.distributionCharts[k].update);

View File

@ -21,13 +21,6 @@ module.context.use(router);
const LDJSON = 'application/x-ldjson'; const LDJSON = 'application/x-ldjson';
const legacyErrors = new Map([
[errors.ERROR_SERVICE_INVALID_NAME.code, errors.ERROR_SERVICE_SOURCE_NOT_FOUND.code],
[errors.ERROR_SERVICE_INVALID_MOUNT.code, errors.ERROR_INVALID_MOUNTPOINT.code],
[errors.ERROR_SERVICE_DOWNLOAD_FAILED.code, errors.ERROR_SERVICE_SOURCE_ERROR.code],
[errors.ERROR_SERVICE_UPLOAD_FAILED.code, errors.ERROR_SERVICE_SOURCE_ERROR.code]
]);
const serviceToJson = (service) => ( const serviceToJson = (service) => (
{ {
mount: service.mount, mount: service.mount,
@ -70,9 +63,8 @@ router.use((req, res, next) => {
next(); next();
} catch (e) { } catch (e) {
if (e.isArangoError) { if (e.isArangoError) {
const errorNum = legacyErrors.get(e.errorNum) || e.errorNum; const status = actions.arangoErrorToHttpCode(e.errorNum);
const status = actions.arangoErrorToHttpCode(errorNum); res.throw(status, e.errorMessage, {errorNum: e.errorNum, cause: e});
res.throw(status, e.errorMessage, {errorNum, cause: e});
} }
throw e; throw e;
} }

View File

@ -406,17 +406,6 @@ exports.stringPadding = function (str, len, pad, dir) {
return str; return str;
}; };
// //////////////////////////////////////////////////////////////////////////////
// / @brief throws an error in case a download failed
// //////////////////////////////////////////////////////////////////////////////
exports.throwDownloadError = function (msg) {
throw new exports.ArangoError({
errorNum: exports.errors.ERROR_SERVICE_DOWNLOAD_FAILED.code,
errorMessage: exports.errors.ERROR_SERVICE_DOWNLOAD_FAILED.message + ': ' + String(msg)
});
};
// ////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////
// / @brief throws an error in case of missing file // / @brief throws an error in case of missing file
// ////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////

View File

@ -27,12 +27,14 @@
// / @author Copyright 2015, triAGENS GmbH, Cologne, Germany // / @author Copyright 2015, triAGENS GmbH, Cologne, Germany
// ////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////
const dd = require('dedent');
const arangodb = require('@arangodb'); const arangodb = require('@arangodb');
const plainServerVersion = arangodb.plainServerVersion; const plainServerVersion = arangodb.plainServerVersion;
const db = arangodb.db; const db = arangodb.db;
const errors = arangodb.errors;
const ArangoError = arangodb.ArangoError;
const download = require('internal').download; const download = require('internal').download;
const fs = require('fs'); const fs = require('fs');
const throwDownloadError = arangodb.throwDownloadError;
const utils = require('@arangodb/foxx/manager-utils'); const utils = require('@arangodb/foxx/manager-utils');
const semver = require('semver'); const semver = require('semver');
@ -326,7 +328,14 @@ var update = function () {
}, filename); }, filename);
if (result.code < 200 || result.code > 299) { if (result.code < 200 || result.code > 299) {
throwDownloadError("Github download from '" + url + "' failed with error code " + result.code); throw new ArangoError({
errorNum: errors.ERROR_SERVICE_SOURCE_ERROR.code,
errorMessage: dd`
${errors.ERROR_SERVICE_SOURCE_ERROR.message}
URL: ${url}
Status Code: ${result.code}
`
});
} }
updateFishbowlFromZip(filename); updateFishbowlFromZip(filename);

View File

@ -110,13 +110,8 @@ describe('Foxx Manager install', function () {
expect(function () { expect(function () {
FoxxManager.install(fs.join(basePath, 'malformed-controller-path'), '/unittest/broken'); FoxxManager.install(fs.join(basePath, 'malformed-controller-path'), '/unittest/broken');
}).to.throw(ArangoError).that.satisfies(function (err) { }).to.throw(ArangoError).that.satisfies(function (err) {
expect(err).to.have.property('errorNum', errors.ERROR_MODULE_FAILURE.code); expect(err).to.have.property('errorNum', errors.ERROR_MODULE_NOT_FOUND.code);
if (require('@arangodb').isServer) {
expect(err).to.have.property('cause').that.is.an.instanceof(ArangoError)
.with.a.property('errorNum', errors.ERROR_SYS_ERROR.code);
} else {
expect(err).not.to.have.property('cause'); expect(err).not.to.have.property('cause');
}
return true; return true;
}); });
}); });
@ -125,11 +120,10 @@ describe('Foxx Manager install', function () {
expect(function () { expect(function () {
FoxxManager.install(fs.join(basePath, 'broken-controller-file'), '/unittest/broken'); FoxxManager.install(fs.join(basePath, 'broken-controller-file'), '/unittest/broken');
}).to.throw(ArangoError).that.satisfies(function (err) { }).to.throw(ArangoError).that.satisfies(function (err) {
expect(err).to.have.property('errorNum', errors.ERROR_MODULE_FAILURE.code); expect(err).to.have.property('errorNum', errors.ERROR_MODULE_SYNTAX_ERROR.code);
if (require('@arangodb').isServer) { if (require('@arangodb').isServer) {
expect(err).to.have.property('cause'); expect(err).to.have.property('cause')
expect(err.cause).not.to.be.an.instanceof(SyntaxError); .that.is.an.instanceof(SyntaxError);
expect(err.cause).not.to.be.an.instanceof(ArangoError);
} else { } else {
expect(err).not.to.have.property('cause'); expect(err).not.to.have.property('cause');
} }
@ -188,14 +182,8 @@ describe('Foxx Manager install', function () {
expect(function () { expect(function () {
FoxxManager.install(fs.join(basePath, 'malformed-exports-path'), '/unittest/broken'); FoxxManager.install(fs.join(basePath, 'malformed-exports-path'), '/unittest/broken');
}).to.throw(ArangoError).that.satisfies(function (err) { }).to.throw(ArangoError).that.satisfies(function (err) {
expect(err).to.have.property('errorNum', errors.ERROR_MODULE_FAILURE.code); expect(err).to.have.property('errorNum', errors.ERROR_MODULE_NOT_FOUND.code);
if (require('@arangodb').isServer) {
expect(err).to.have.property('cause')
.that.is.an.instanceof(ArangoError)
.with.a.property('errorNum', errors.ERROR_SYS_ERROR.code);
} else {
expect(err).not.to.have.property('cause'); expect(err).not.to.have.property('cause');
}
return true; return true;
}); });
}); });
@ -219,14 +207,8 @@ describe('Foxx Manager install', function () {
expect(function () { expect(function () {
FoxxManager.install(fs.join(basePath, 'malformed-setup-path'), '/unittest/broken'); FoxxManager.install(fs.join(basePath, 'malformed-setup-path'), '/unittest/broken');
}).to.throw(ArangoError).that.satisfies(function (err) { }).to.throw(ArangoError).that.satisfies(function (err) {
expect(err).to.have.property('errorNum', errors.ERROR_MODULE_FAILURE.code); expect(err).to.have.property('errorNum', errors.ERROR_MODULE_NOT_FOUND.code);
if (require('@arangodb').isServer) {
expect(err).to.have.property('cause')
.that.is.an.instanceof(ArangoError)
.with.a.property('errorNum', errors.ERROR_SYS_ERROR.code);
} else {
expect(err).not.to.have.property('cause'); expect(err).not.to.have.property('cause');
}
return true; return true;
}); });
}); });
@ -235,14 +217,8 @@ describe('Foxx Manager install', function () {
expect(function () { expect(function () {
FoxxManager.install(fs.join(basePath, 'missing-controller-file'), '/unittest/broken'); FoxxManager.install(fs.join(basePath, 'missing-controller-file'), '/unittest/broken');
}).to.throw(ArangoError).that.satisfies(function (err) { }).to.throw(ArangoError).that.satisfies(function (err) {
expect(err).to.have.property('errorNum', errors.ERROR_MODULE_FAILURE.code); expect(err).to.have.property('errorNum', errors.ERROR_MODULE_NOT_FOUND.code);
if (require('@arangodb').isServer) {
expect(err).to.have.property('cause')
.that.is.an.instanceof(ArangoError)
.with.a.property('errorNum', errors.ERROR_SYS_ERROR.code);
} else {
expect(err).not.to.have.property('cause'); expect(err).not.to.have.property('cause');
}
return true; return true;
}); });
}); });
@ -251,14 +227,8 @@ describe('Foxx Manager install', function () {
expect(function () { expect(function () {
FoxxManager.install(fs.join(basePath, 'missing-exports-file'), '/unittest/broken'); FoxxManager.install(fs.join(basePath, 'missing-exports-file'), '/unittest/broken');
}).to.throw(ArangoError).that.satisfies(function (err) { }).to.throw(ArangoError).that.satisfies(function (err) {
expect(err).to.have.property('errorNum', errors.ERROR_MODULE_FAILURE.code); expect(err).to.have.property('errorNum', errors.ERROR_MODULE_NOT_FOUND.code);
if (require('@arangodb').isServer) {
expect(err).to.have.property('cause')
.that.is.an.instanceof(ArangoError)
.with.a.property('errorNum', errors.ERROR_SYS_ERROR.code);
} else {
expect(err).not.to.have.property('cause'); expect(err).not.to.have.property('cause');
}
return true; return true;
}); });
}); });
@ -267,14 +237,8 @@ describe('Foxx Manager install', function () {
expect(function () { expect(function () {
FoxxManager.install(fs.join(basePath, 'missing-setup-file'), '/unittest/broken'); FoxxManager.install(fs.join(basePath, 'missing-setup-file'), '/unittest/broken');
}).to.throw(ArangoError).that.satisfies(function (err) { }).to.throw(ArangoError).that.satisfies(function (err) {
expect(err).to.have.property('errorNum', errors.ERROR_MODULE_FAILURE.code); expect(err).to.have.property('errorNum', errors.ERROR_MODULE_NOT_FOUND.code);
if (require('@arangodb').isServer) {
expect(err).to.have.property('cause')
.that.is.an.instanceof(ArangoError)
.with.a.property('errorNum', errors.ERROR_SYS_ERROR.code);
} else {
expect(err).not.to.have.property('cause'); expect(err).not.to.have.property('cause');
}
return true; return true;
}); });
}); });