Skip to content
This repository was archived by the owner on May 3, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions bin/matrix-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ t = Matrix.localization.get; // international translator


Matrix.helpers = require('../lib/helpers');
Matrix.error = Matrix.helpers.error;
//sets Matrix.config with local variables
Matrix.config = _.assign(Matrix.config, Matrix.helpers.getConfig());
//set default locale
Expand Down
2 changes: 1 addition & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async.series([
async.apply(Matrix.api.app.trigger, Matrix.config.device.identifier, 'amazing-matrix-ping')
], function (err) {
if (err) {
console.error(err.message.red);
Matrix.error(err); //Print error
debug('Error:', err);
}
return endIt();
Expand Down
18 changes: 18 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ const installTimeoutSeconds = 30; //seconds to get a install response from devic

var configFile = require('os').homedir() + '/.matrix/store.json';

/**
* Prints a friendly error message to the terminal including source if provided
* @param {Error|String} err Error object or Error message string to print
* @param {String} source Source of the error, this will be included before the error in the following format (<source>)
*/
function error(err, source) {
if (err) {
var errorMessage = err.message ? err.message : err; //Fetch message
if (typeof errorMessage === 'string') errorMessage = errorMessage.red; //Paint it red
else if (!(err instanceof Error)) errorMessage = JSON.stringify(errorMessage); //This is a little hackish, could be removed if undesired
if (source && typeof source === 'string') errorMessage = '(' + source.yellow + ') ' + errorMessage; //Add (source): <err>
console.error(errorMessage); //Actually print the error message
} else {
debug('Unable to print error'.yellow, err);
}
}

function trackEvent(eventName, extras, cb) {

debug('Track Event'.yellow, eventName, extras);
Expand Down Expand Up @@ -1407,6 +1424,7 @@ module.exports = {
displayGroups: displayGroups,
displayKeyValue: displayKeyValue,
displaySearch: displaySearch,
error: error,
formAppData: formAppData,
getConfig: getConfig,
getUploadUrl: getUploadUrl,
Expand Down