From 5fe5db603d685419410193ca80c46586476736d1 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 5 Feb 2018 15:59:11 +0000 Subject: [PATCH] Better error handling/reporting in project creation --- editor/js/ui/projects/projectSettings.js | 27 +++++----- editor/js/ui/projects/projects.js | 50 +++++++++++++++++-- editor/js/ui/projects/tab-versionControl.js | 4 +- red/api/editor/projects/index.js | 7 ++- .../localfilesystem/projects/Project.js | 41 ++++----------- .../localfilesystem/projects/git/index.js | 4 ++ 6 files changed, 79 insertions(+), 54 deletions(-) diff --git a/editor/js/ui/projects/projectSettings.js b/editor/js/ui/projects/projectSettings.js index 249f92ffa..a1c2a928a 100644 --- a/editor/js/ui/projects/projectSettings.js +++ b/editor/js/ui/projects/projectSettings.js @@ -143,7 +143,8 @@ RED.projects.settings = (function() { RED.sidebar.versionControl.refresh(true); }, 400: { - 'unexpected_error': function(error) { + '*': function(error) { + utils.reportUnexpectedError(error); done(error,null); } }, @@ -208,7 +209,8 @@ RED.projects.settings = (function() { done(null,data); }, 400: { - 'unexpected_error': function(error) { + '*': function(error) { + utils.reportUnexpectedError(error); done(error,null); } }, @@ -962,7 +964,7 @@ RED.projects.settings = (function() { var done = function(err) { spinner.remove(); if (err) { - console.log(err); + utils.reportUnexpectedError(err); return; } flowFileLabelText.text(flowFileInput.val()); @@ -1005,10 +1007,6 @@ RED.projects.settings = (function() { 'credentials_load_failed': function(error) { done(error); }, - 'unexpected_error': function(error) { - console.log(error); - done(error); - }, 'missing_current_credential_key': function(error) { credentialSecretExistingInput.addClass("input-error"); popover = RED.popover.create({ @@ -1019,6 +1017,9 @@ RED.projects.settings = (function() { autoClose: 3000 }).open(); done(error); + }, + '*': function(error) { + done(error); } }, } @@ -1142,8 +1143,8 @@ RED.projects.settings = (function() { ] }); }, - 'unexpected_error': function(error) { - console.log(error); + '*': function(error) { + utils.reportUnexpectedError(error); spinner.remove(); } }, @@ -1277,8 +1278,8 @@ RED.projects.settings = (function() { }); }, 400: { - 'unexpected_error': function(error) { - console.log(error); + '*': function(error) { + utils.reportUnexpectedError(error); spinner.remove(); } }, @@ -1404,8 +1405,8 @@ RED.projects.settings = (function() { remoteNameInput.addClass('input-error'); done(error); }, - 'unexpected_error': function(error) { - console.log(error); + '*': function(error) { + utils.reportUnexpectedError(error); done(error); } }, diff --git a/editor/js/ui/projects/projects.js b/editor/js/ui/projects/projects.js index 1883cd399..1f911cc1a 100644 --- a/editor/js/ui/projects/projects.js +++ b/editor/js/ui/projects/projects.js @@ -19,7 +19,45 @@ RED.projects = (function() { var dialogBody; var activeProject; - + function reportUnexpectedError(error) { + var notification; + if (error.error === 'git_missing_user') { + notification = RED.notify("

You Git client is not configured with a username/email.

",{ + 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("

An unexpected error occurred:

"+error.message+"

code: "+error.error+"",{ + fixed: true, + modal: true, + type: 'error', + buttons: [ + { + text: "Close", + click: function() { + notification.close(); + } + } + ] + }) + } + } var screens = {}; function initScreens() { var migrateProjectHeader = $('
'); @@ -565,8 +603,9 @@ RED.projects = (function() { // getRepoAuthDetails(req); console.log("git auth error",error); }, - 'unexpected_error': function(error) { - console.log("unexpected_error",error) + '*': function(error) { + reportUnexpectedError(error); + $( dialog ).dialog( "close" ); } } } @@ -1753,7 +1792,7 @@ RED.projects = (function() { RED.notify(error.message,'error'); }, 'unexpected_error': function(error) { - console.log(error); + reportUnexpectedError(error); } } } @@ -1800,7 +1839,8 @@ RED.projects = (function() { var projectsAPI = { sendRequest:sendRequest, createBranchList:createBranchList, - addSpinnerOverlay:addSpinnerOverlay + addSpinnerOverlay:addSpinnerOverlay, + reportUnexpectedError:reportUnexpectedError }; RED.projects.settings.init(projectsAPI); RED.projects.userSettings.init(projectsAPI); diff --git a/editor/js/ui/projects/tab-versionControl.js b/editor/js/ui/projects/tab-versionControl.js index c3131ad57..04aafd23a 100644 --- a/editor/js/ui/projects/tab-versionControl.js +++ b/editor/js/ui/projects/tab-versionControl.js @@ -487,8 +487,8 @@ RED.sidebar.versionControl = (function() { refresh(true); }, 400: { - 'unexpected_error': function(error) { - console.log(error); + '*': function(error) { + utils.reportUnexpectedError(error); } }, } diff --git a/red/api/editor/projects/index.js b/red/api/editor/projects/index.js index 96cf54609..ef6823d38 100644 --- a/red/api/editor/projects/index.js +++ b/red/api/editor/projects/index.js @@ -248,8 +248,11 @@ module.exports = { res.redirect(303,req.baseUrl+"/"+projectName+"/status"); }) .catch(function(err) { - console.log(err.stack); - res.status(400).json({error:"unexpected_error", message:err.toString()}); + if (err.code) { + res.status(400).json({error:err.code, message: err.message}); + } else { + res.status(400).json({error:"unexpected_error", message:err.toString()}); + } }) }); diff --git a/red/runtime/storage/localfilesystem/projects/Project.js b/red/runtime/storage/localfilesystem/projects/Project.js index dff62f2c8..8651ecc1a 100644 --- a/red/runtime/storage/localfilesystem/projects/Project.js +++ b/red/runtime/storage/localfilesystem/projects/Project.js @@ -912,40 +912,17 @@ function createProject(user, metadata) { ); auth = authCache.get(project,originRemote.url,username); } - return gitTools.clone(originRemote,auth,projectPath).then(function(result) { - // 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); - }); - }) + return gitTools.clone(originRemote,auth,projectPath); } 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); + }); + }); }) }) } diff --git a/red/runtime/storage/localfilesystem/projects/git/index.js b/red/runtime/storage/localfilesystem/projects/git/index.js index 01b6f5e45..12e2894ab 100644 --- a/red/runtime/storage/localfilesystem/projects/git/index.js +++ b/red/runtime/storage/localfilesystem/projects/git/index.js @@ -73,6 +73,10 @@ function runGitCommand(args,cwd,env) { err.code = "git_repository_not_found"; } else if (/refusing to merge unrelated histories/.test(stderr)) { 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); }