Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-13908] Added better error handling with logging in/out and saving... #42

Merged
merged 1 commit into from
Jun 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
3.2.0
-------------------
* Added better error handling with logging in and out of the Appc network; saving cli config [TIMOB-13908]

3.1.1
-------------------
* Added support for code processor plugin paths [TIMOB-13118]
Expand Down
10 changes: 8 additions & 2 deletions lib/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ exports.config = function (logger, config, cli) {
exports.run = function (logger, config, cli) {
appc.auth.login(cli.argv.username, cli.argv.password, function(result) {
if (result.error) {
logger.log(__('Login failed: %s', result.error) + '\n');
if (result.error.type == 'AppcException') {
result.error.dump(logger.error);
} else {
logger.error(result.error.toString().trim());
}
result.hasOwnProperty('loggedIn') && logger.error(__(result.loggedIn ? 'You are still logged in' : 'You are currently logged out'));
} else {
logger.log(__('Logged in successfully') + '\n');
logger.log(__('Logged in successfully'));
}
logger.log();
}, config.cli.httpProxyServer);
};
14 changes: 11 additions & 3 deletions lib/commands/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ exports.config = function (logger, config, cli) {

exports.run = function (logger, config, cli) {
appc.auth.logout(function (result) {
if (result.alreadyLoggedOut) {
logger.log(__('Already logged out') + '\n');
if (result.error) {
if (result.error.type == 'AppcException') {
result.error.dump(logger.error);
} else {
logger.error(result.error.toString().trim());
}
result.hasOwnProperty('loggedIn') && logger.error(__(result.loggedIn ? 'You are still logged in' : 'You are currently logged out'));
} else if (result.alreadyLoggedOut) {
logger.log(__('Already logged out'));
} else {
logger.log(__('Logged out successfully') + '\n');
logger.log(__('Logged out successfully'));
}
logger.log();
}, config.cli.httpProxyServer);
};
17 changes: 14 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,21 @@ Object.defineProperty(config, 'load', {

Object.defineProperty(config, 'save', {
value: function () {
if (!fs.existsSync(titaniumConfigFolder)) {
wrench.mkdirSyncRecursive(titaniumConfigFolder);
try {
if (!fs.existsSync(titaniumConfigFolder)) {
wrench.mkdirSyncRecursive(titaniumConfigFolder);
}
fs.writeFileSync(configFile, JSON.stringify(config, null, '\t'));
} catch (e) {
if (e.code == 'EACCES') {
tierror(__('Unable to write config file %s', configFile));
tierror(__('Please ensure the Titanium CLI has access to modify this file.') + '\n');
} else {
tierror(__('An error occurred trying to save the Titanium CLI config file.'));
tierror((e.stack || e.toString()) + '\n');
}
process.exit(1);
}
fs.writeFileSync(configFile, JSON.stringify(config, null, '\t'));
}
});

Expand Down
19 changes: 16 additions & 3 deletions lib/titanium.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function run() {
directory: path.join('~', '.titanium'),
version: pkginfo.version,
deployType: 'production',
httpProxyServer: config.cli.httpProxyServer
httpProxyServer: config.cli.httpProxyServer,
showErrors: false
}, appc.auth.status()));
}

Expand Down Expand Up @@ -255,7 +256,19 @@ function run() {
(cli.sdk != null && cli.cmds[cmd][cli.sdk.name] && cli.cmds[cmd][cli.sdk.name].__global__ && cli.cmds[cmd][cli.sdk.name].__global__.skipBanner)
))) {
logger.banner();

if (logger.bannerWasRendered()) {
// check if the analytics files are writable
var pp = ['~/.titanium/analytics.json', '~/.titanium/analytics_session.json'].filter(function (p) {
return !afs.isFileWritable(p);
}).shift();
if (pp) {
console.warn(__('Required file %s is not writable.', pp).split(pp).map(function (p) { return p.yellow; }).join(pp.cyan));
console.warn(__('Please ensure the Titanium CLI has access to modify this file.').yellow + '\n');
}
}
}

next();
},
cli.validate,
Expand All @@ -264,8 +277,8 @@ function run() {
if (logger.bannerWasRendered() && enc && !config.cli.hideCharEncWarning) {
enc = enc.split('.');
if (enc.length > 1 && enc[enc.length-1].toLowerCase() != 'utf-8') {
console.log(__('Detected terminal character encoding as "%s". Some characters may not render properly.', enc[enc.length-1]).yellow);
console.log(__('It is recommended that you change the character encoding to UTF-8.').yellow + '\n');
console.warn(__('Detected terminal character encoding as "%s". Some characters may not render properly.', enc[enc.length-1]).yellow);
console.warn(__('It is recommended that you change the character encoding to UTF-8.').yellow + '\n');
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"async": "0.1.x",
"colors": "0.6.x",
"longjohn": ">=0.0.3",
"node-appc": "0.1.29",
"node-appc": "0.1.30",
"prompt": "0.2.x",
"request": "2.9.x",
"revalidator": "0.1.x",
Expand Down