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);
},
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);
}
},

View File

@ -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("<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 = {};
function initScreens() {
var migrateProjectHeader = $('<div class="projects-dialog-screen-start-hero"></div>');
@ -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);

View File

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

View File

@ -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()});
}
})
});

View File

@ -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);
});
});
})
})
}

View File

@ -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);
}