1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Better error handling/reporting in project creation

This commit is contained in:
Nick O'Leary 2018-02-05 15:59:11 +00:00
parent 9f7dd7f5d4
commit 5fe5db603d
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
6 changed files with 79 additions and 54 deletions

View File

@ -143,7 +143,8 @@ RED.projects.settings = (function() {
RED.sidebar.versionControl.refresh(true); RED.sidebar.versionControl.refresh(true);
}, },
400: { 400: {
'unexpected_error': function(error) { '*': function(error) {
utils.reportUnexpectedError(error);
done(error,null); done(error,null);
} }
}, },
@ -208,7 +209,8 @@ RED.projects.settings = (function() {
done(null,data); done(null,data);
}, },
400: { 400: {
'unexpected_error': function(error) { '*': function(error) {
utils.reportUnexpectedError(error);
done(error,null); done(error,null);
} }
}, },
@ -962,7 +964,7 @@ RED.projects.settings = (function() {
var done = function(err) { var done = function(err) {
spinner.remove(); spinner.remove();
if (err) { if (err) {
console.log(err); utils.reportUnexpectedError(err);
return; return;
} }
flowFileLabelText.text(flowFileInput.val()); flowFileLabelText.text(flowFileInput.val());
@ -1005,10 +1007,6 @@ RED.projects.settings = (function() {
'credentials_load_failed': function(error) { 'credentials_load_failed': function(error) {
done(error); done(error);
}, },
'unexpected_error': function(error) {
console.log(error);
done(error);
},
'missing_current_credential_key': function(error) { 'missing_current_credential_key': function(error) {
credentialSecretExistingInput.addClass("input-error"); credentialSecretExistingInput.addClass("input-error");
popover = RED.popover.create({ popover = RED.popover.create({
@ -1019,6 +1017,9 @@ RED.projects.settings = (function() {
autoClose: 3000 autoClose: 3000
}).open(); }).open();
done(error); done(error);
},
'*': function(error) {
done(error);
} }
}, },
} }
@ -1142,8 +1143,8 @@ RED.projects.settings = (function() {
] ]
}); });
}, },
'unexpected_error': function(error) { '*': function(error) {
console.log(error); utils.reportUnexpectedError(error);
spinner.remove(); spinner.remove();
} }
}, },
@ -1277,8 +1278,8 @@ RED.projects.settings = (function() {
}); });
}, },
400: { 400: {
'unexpected_error': function(error) { '*': function(error) {
console.log(error); utils.reportUnexpectedError(error);
spinner.remove(); spinner.remove();
} }
}, },
@ -1404,8 +1405,8 @@ RED.projects.settings = (function() {
remoteNameInput.addClass('input-error'); remoteNameInput.addClass('input-error');
done(error); done(error);
}, },
'unexpected_error': function(error) { '*': function(error) {
console.log(error); utils.reportUnexpectedError(error);
done(error); done(error);
} }
}, },

View File

@ -19,7 +19,45 @@ RED.projects = (function() {
var dialogBody; var dialogBody;
var activeProject; var activeProject;
function reportUnexpectedError(error) {
var notification;
if (error.error === 'git_missing_user') {
notification = RED.notify("<p>You Git client is not configured with a username/email.</p>",{
fixed: true,
type:'error',
buttons: [
{
text: "Cancel",
click: function() {
notification.close();
}
},
{
text: "Configure Git client",
click: function() {
RED.userSettings.show('gitconfig');
notification.close();
}
}
]
})
} else {
console.log(error);
notification = RED.notify("<p>An unexpected error occurred:</p><p>"+error.message+"</p><small>code: "+error.error+"</small>",{
fixed: true,
modal: true,
type: 'error',
buttons: [
{
text: "Close",
click: function() {
notification.close();
}
}
]
})
}
}
var screens = {}; var screens = {};
function initScreens() { function initScreens() {
var migrateProjectHeader = $('<div class="projects-dialog-screen-start-hero"></div>'); var migrateProjectHeader = $('<div class="projects-dialog-screen-start-hero"></div>');
@ -565,8 +603,9 @@ RED.projects = (function() {
// getRepoAuthDetails(req); // getRepoAuthDetails(req);
console.log("git auth error",error); console.log("git auth error",error);
}, },
'unexpected_error': function(error) { '*': function(error) {
console.log("unexpected_error",error) reportUnexpectedError(error);
$( dialog ).dialog( "close" );
} }
} }
} }
@ -1753,7 +1792,7 @@ RED.projects = (function() {
RED.notify(error.message,'error'); RED.notify(error.message,'error');
}, },
'unexpected_error': function(error) { 'unexpected_error': function(error) {
console.log(error); reportUnexpectedError(error);
} }
} }
} }
@ -1800,7 +1839,8 @@ RED.projects = (function() {
var projectsAPI = { var projectsAPI = {
sendRequest:sendRequest, sendRequest:sendRequest,
createBranchList:createBranchList, createBranchList:createBranchList,
addSpinnerOverlay:addSpinnerOverlay addSpinnerOverlay:addSpinnerOverlay,
reportUnexpectedError:reportUnexpectedError
}; };
RED.projects.settings.init(projectsAPI); RED.projects.settings.init(projectsAPI);
RED.projects.userSettings.init(projectsAPI); RED.projects.userSettings.init(projectsAPI);

View File

@ -487,8 +487,8 @@ RED.sidebar.versionControl = (function() {
refresh(true); refresh(true);
}, },
400: { 400: {
'unexpected_error': function(error) { '*': function(error) {
console.log(error); utils.reportUnexpectedError(error);
} }
}, },
} }

View File

@ -248,8 +248,11 @@ module.exports = {
res.redirect(303,req.baseUrl+"/"+projectName+"/status"); res.redirect(303,req.baseUrl+"/"+projectName+"/status");
}) })
.catch(function(err) { .catch(function(err) {
console.log(err.stack); if (err.code) {
res.status(400).json({error:"unexpected_error", message:err.toString()}); res.status(400).json({error:err.code, message: err.message});
} else {
res.status(400).json({error:"unexpected_error", message:err.toString()});
}
}) })
}); });

View File

@ -912,40 +912,17 @@ function createProject(user, metadata) {
); );
auth = authCache.get(project,originRemote.url,username); auth = authCache.get(project,originRemote.url,username);
} }
return gitTools.clone(originRemote,auth,projectPath).then(function(result) { return gitTools.clone(originRemote,auth,projectPath);
// Check this is a valid project
// If it is empty
// - if 'populate' flag is set, call populateProject
// - otherwise reject with suitable error to allow UI to confirm population
// If it is missing package.json/flow.json/flow_cred.json
// - reject as invalid project
// checkProjectFiles(project).then(function(results) {
// console.log("checkProjectFiles");
// console.log(results);
// });
// return gitTools.getFiles(projectPath).then(function() {
// // It wasn't an empty repository.
// // TODO: check for required files - checkProjectFiles
//
// }).catch(function(err) {
// if (/ambiguous argument/.test(err.message)) {
// // Empty repository
// err.code = "project_empty";
// err.message = "Project is empty";
// }
// throw err;
// });
resolve(getProject(project));
}).catch(function(error) {
fs.remove(projectPath,function() {
reject(error);
});
})
} else { } else {
createDefaultProject(user, metadata).then(function() { resolve(getProject(project))}).catch(reject); return createDefaultProject(user, metadata);
} }
}).catch(reject); }).then(function() {
resolve(getProject(project))
}).catch(function(err) {
fs.remove(projectPath,function() {
reject(err);
});
});
}) })
}) })
} }

View File

@ -73,6 +73,10 @@ function runGitCommand(args,cwd,env) {
err.code = "git_repository_not_found"; err.code = "git_repository_not_found";
} else if (/refusing to merge unrelated histories/.test(stderr)) { } else if (/refusing to merge unrelated histories/.test(stderr)) {
err.code = "git_pull_unrelated_history" err.code = "git_pull_unrelated_history"
} else if (/Please tell me who you are/.test(stderr)) {
err.code = "git_missing_user";
} else if (/name consists only of disallowed characters/.test(stderr)) {
err.code = "git_missing_user";
} }
return reject(err); return reject(err);
} }