Skip to content

Commit

Permalink
friendlier warnings for missing cusotm response files, or a missing p…
Browse files Browse the repository at this point in the history
…ackage.json, etc. to allow for cleaner usage of sails w/ minimal files.
  • Loading branch information
mikermcneil committed Mar 18, 2014
1 parent 7a260b3 commit 8d2d656
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
27 changes: 27 additions & 0 deletions errors/warn.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,32 @@ module.exports = {
log.warn(' $ npm install sails@' + requiredVersion);
log.warn();
log.blank();
},




// Verbose-only warnings:

noPackageJSON: function() {
log.warn('Cannot read package.json in the current directory (' + process.cwd() + ')');
log.warn('Are you sure this is a Sails app?');
log.warn();
},

notSailsApp: function() {
log.warn('The package.json in the current directory does not list Sails as a dependency...');
log.warn('Are you sure `' + process.cwd() + '` is a Sails app?');
log.warn();
},

badLocalDependency: function(pathTo_localSails, requiredVersion) {
log.warn(
'The local Sails dependency installed at `' + pathTo.localSails + '` ' +
'has a corrupted, missing, or un-parsable package.json file.'
);
log.warn('You may consider running:');
log.warn('rm -rf ' + pathTo_localSails + ' && npm install sails@' + app.dependencies.sails);
log.warn();
}
};
7 changes: 3 additions & 4 deletions lib/app/isLocalSailsValid.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ module.exports = function isLocalSailsValid ( sailsPath, appPath ) {

// Has no package.json file
if ( ! fs.existsSync( appPath + '/package.json') ) {
Err.fatal.noPackageJSON();
return;
Err.warn.noPackageJSON();
}

// Load this app's package.json and dependencies
Expand All @@ -31,7 +30,7 @@ module.exports = function isLocalSailsValid ( sailsPath, appPath ) {

// Package.json exists, but doesn't list Sails as a dependency
if ( !(appDependencies && appDependencies.sails) ) {
Err.fatal.notSailsApp();
Err.warn.notSailsApp();
return;
}

Expand All @@ -45,7 +44,7 @@ module.exports = function isLocalSailsValid ( sailsPath, appPath ) {

// Local Sails has a corrupted package.json
if ( !sailsPackageJSON ) {
Err.fatal.badLocalDependency(sailsPath, appDependencies.sails);
Err.warn.badLocalDependency(sailsPath, appDependencies.sails);
return;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/hooks/responses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@ module.exports = function(sails) {
* @return {Function}
*/
function cannotFindResponseWarning (responseName, statusCode) {
return function _mockCustomResponse () {
return function _mockCustomResponse (err) {
var req = this.req;
var res = this.res;

// Log a warning:
var warningMsg = '`res.%s()` was called, but no response module was found for `%s`.';
warningMsg = util.format(warningMsg, responseName, responseName);
sails.log.warn(warningMsg);
// sails.log.warn(warningMsg);
var helpMsg = 'You can probably solve this by creating `%s.js` in:';
helpMsg = util.format(helpMsg, responseName);
sails.log.warn(helpMsg);
sails.log.warn(sails.config.paths.responses);
// sails.log.warn(helpMsg);
// sails.log.warn(sails.config.paths.responses);

// Send a default response:
if (process.env.NODE_ENV === 'production') {
return res.send(statusCode || 500);
}
return res.send(statusCode || 500, warningMsg);
return res.send(statusCode || 500, err);
};
}
},
Expand Down

0 comments on commit 8d2d656

Please sign in to comment.