Skip to content

Commit

Permalink
removed negative cmdSync exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
ktrzeciaknubisa committed Mar 2, 2015
1 parent 41d257f commit 3bd08d9
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 59 deletions.
2 changes: 1 addition & 1 deletion lib/jx/_jx_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var applyConfig = function(formPath, content) {
.error(
"Application couldn't start because of the configuration file is either corrupted or not accessible.",
e);
process.exit(-1);
process.exit(1);
}
}
};
Expand Down
21 changes: 13 additions & 8 deletions lib/jx/_jx_monitorHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var stopIt = function(restart) {
mon.checkMonitorExists(function(err, msg) {
if (!err) {
mon.stopMonitor(function() {
process.exit(-1);
// exit without error
process.exit(0);
});
console.log("Monitoring service is closed.");
} else {
Expand All @@ -25,6 +26,9 @@ var stopIt = function(restart) {

if (restart) {
startIt();
} else {
if (err)
process.exit(1);
}
});
};
Expand All @@ -51,7 +55,8 @@ var startMon = function() {
if (fs.existsSync("./jxcore.monitor.console.log")) {
console.log(fs.readFileSync('./jxcore.monitor.console.log') + "");
console.log("");
process.exit(-1);
// exit without error
process.exit(0);
} else {
mon.checkMonitorExists(function(err, msg) {
if (!err) {
Expand All @@ -63,7 +68,7 @@ var startMon = function() {
if (msg) console.error(msg);

console.log("");
process.exit(-1);
process.exit(err ? 1 : 0);
});
}
}, 2000);
Expand All @@ -76,7 +81,7 @@ var startIt = function() {
mon.checkMonitorExists(function(err, msg) {
if (!err) {
console.log(color.setColor('Monitoring is already active', "red+bold"));
process.exit(-1);
process.exit(1);
} else {
startMon();
}
Expand All @@ -91,7 +96,7 @@ try {
console.log("");
console.log("usage: jx monitor run [applicationfile]");
console.log("");
process.exit(-1);
process.exit(1);
} else {
process.argv[3] = path.resolve(process.argv[3]);

Expand All @@ -105,7 +110,7 @@ try {
color.log("Application monitoring is failed.", 'red+bold');
if (msg) console.error(msg);
console.log("");
process.exit(-1);
process.exit(1);
} else {
var h = require(process.argv[3]);
}
Expand All @@ -132,7 +137,7 @@ try {
color.log("Kill operation is failed.", 'red+bold');
if (msg) console.error(msg);
console.log("");
process.exit(-1);
process.exit(1);
} else {
console.log("Process with given path is killed.");
}
Expand All @@ -144,5 +149,5 @@ try {
} catch (e) {
color.log("Error:" + e, 'red+bold');
console.log('');
process.exit(-1);
process.exit(1);
}
2 changes: 1 addition & 1 deletion lib/jx/_jx_multiplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var method = {
require.resolve(process.argv[2]);
} catch(e) {
console.error("could not resolve ", process.argv[2]);
process.exit(-1);
process.exit(1);
}

require(process.argv[2], null, null, true);
Expand Down
2 changes: 1 addition & 1 deletion lib/jx/_jx_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (process._EmbeddedSource) {

if (!src) {
console.error("embedded source file wasn't exist");
process.exit(-1);
process.exit(1);
}
require("jx_source.jx", null, null, null, src);
}
4 changes: 2 additions & 2 deletions samples/jx_packaging/dren.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
**/
if(typeof jxcore == 'undefined'){
console.error('This application requires jxcore to run.');
process.exit(-1);
process.exit(1);
}

var fs = require('fs');
var pathModule = require('path');
var log = jxcore.utils.console.log;
var args = process.argv;
var check = function(c, m){if(!c){log(m, "red");process.exit(-1);}};
var check = function(c, m){if(!c){log(m, "red");process.exit(1);}};

check(process.platform == 'win32', "This application is Windows only, you don't need this functionality on other systems");
check(args.length==4, "Requires a path for the .node file and a new target");
Expand Down
48 changes: 24 additions & 24 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
} catch (e) {
co.error("Perhaps the path you are running on is not "
+ "exist any more. Please revisit the path and try again.");
process.exit(-1);
process.exit(1);
}
return sep;
};
Expand All @@ -221,7 +221,7 @@
process.IsEmbedded = IsEmbedded;
} else {
co.error("Binary corrupted");
process.exit(-1);
process.exit(1);
}
}
if (!process.IsEmbedded) {
Expand Down Expand Up @@ -1240,7 +1240,7 @@
} catch (e) {
console
.error("Error: You may not have a read access on current folder or a file system link to current folder removed. Please revisit the folder and make sure you have an access.");
process.exit(-1);
process.exit(1);
}
var isWindows = process.platform === 'win32';

Expand Down Expand Up @@ -1507,7 +1507,7 @@

if (ext != '.jxp') {
console.log("unknown JX project type '" + fn + "'", "red");
process.exit(-1);
process.exit(1);
return;
}

Expand All @@ -1518,7 +1518,7 @@
proj = JSON.parse(stripBOM(xt));
} catch (e) {
console.log(e);
process.exit(-1);
process.exit(1);
return;
}

Expand All @@ -1528,7 +1528,7 @@

if (!proj) {
console.log("corrupted JSON in jxp file", "red");
process.exit(-1);
process.exit(1);
return;
}

Expand All @@ -1538,7 +1538,7 @@
console
.log("no target source file definition inside the j" + "xp",
"red");
process.exit(-1);
process.exit(1);
return;
}

Expand All @@ -1549,7 +1549,7 @@
console.log(
"'name', 'version' and 'output' fields must be defined inside the J"
+ "XP file", "red");
process.exit(-1);
process.exit(1);
return;
}

Expand Down Expand Up @@ -1577,7 +1577,7 @@

if (!proj) {
console.log("corrupted JSON in '" + fn + "' file", red);
process.exit(-1);
process.exit(1);
return;
}

Expand Down Expand Up @@ -1664,7 +1664,7 @@
} catch (e) {
console.log("while processing ", fn_sub, 'red');
console.log(e, 'red');
process.exit(-1);
process.exit(1);
}

var lo = loc.length - 5;
Expand All @@ -1675,7 +1675,7 @@
.log(
"only 'js' or 'json' files can be defined as a source code. (json and js are case sensitive)",
"red");
process.exit(-1);
process.exit(1);
}

var buff;
Expand Down Expand Up @@ -1726,7 +1726,7 @@
_stat = fss.statSync(fn);
} catch (e) {
console.log(e, "red");
process.exit(-1);
process.exit(1);
return;
}

Expand Down Expand Up @@ -1832,21 +1832,21 @@
cmd_sync(op_str);
if (fss.existsSync(file_name + copy_ext)) {
cc("Target file in use", file_name + copy_ext, "red");
process.exit(-1);
process.exit(1);
}
op_str = copy + ' "' + process.execPath + '" "' + file_name + '"';
ret = cmd_sync(op_str);
if (ret.exitCode != 0) {
cc(ret.out, "red");
process.exit(-1);
process.exit(1);
}

if (!fss.existsSync(file_name)) {
cc(
"Couldn't access to JX binary file or write into current folder. "
+ "This is an unexpected error though but you may check the permissions for JX binary file(s) or the current folder",
"red");
process.exit(-1);
process.exit(1);
}

var sz = fss.statSync(file_name);
Expand All @@ -1858,7 +1858,7 @@
if (loc > sz.size - 120) {
cc("\nUnable to compile. Make sure the JX binary is not corrupted",
"red");
process.exit(-1);
process.exit(1);
return;
}
var buffer = new Buffer(56);
Expand Down Expand Up @@ -1906,7 +1906,7 @@
if (loc > sz.size - 120) {
cc("\nUnable to compile. Make sure the JX binary is not corrupted",
"red");
process.exit(-1);
process.exit(1);
return;
}

Expand Down Expand Up @@ -1989,7 +1989,7 @@
try {
res = NativeModule.require('_jx_marker').mark;
} catch (e) {
process.exit(-1);
process.exit(1);
}
if (res && res.trim && res.trim().length < 40) {
if (skip) return true;
Expand All @@ -2001,11 +2001,11 @@
try {
res = parseInt(new Buffer(res, 'hex') + "");
} catch (e) {
process.exit(-1)
process.exit(1)
}
;
if (!res || isNaN(res)) {
process.exit(-1);
process.exit(1);
}
res += 123456789;
res /= 5;
Expand All @@ -2015,11 +2015,11 @@
try {
sz = fs.statSync(process.execPath);
} catch (e) {
process.exit(-1);
process.exit(1);
}
sz.result = res;
if (sz.size - 5000000 < sz.result) {
process.exit(-1);
process.exit(1);
}
try {
var fd = fs.openSync(process.execPath, 'r');
Expand All @@ -2030,7 +2030,7 @@
buffer = null;
process._EmbeddedSource = true;
} catch (e) {
process.exit(-1);
process.exit(1);
}

return true;
Expand Down Expand Up @@ -2168,7 +2168,7 @@
+ ec.out
+ "\n Consider using a custom path from jx.config file's 'npmjxPath' property.");
try {
process.exit(-1);
process.exit(1);
} catch (e) {
}
}
Expand Down
22 changes: 7 additions & 15 deletions src/wrappers/jxutils_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,13 @@ void JXUtilsWrap::exec(const char *cmd, int *ec, std::string &result) {
while (fgets(buffer, 256, pipe)) {
result += buffer;
}
// need checking ferror ?
#if defined(_WIN32)
*ec = _pclose(pipe);
#else
*ec = pclose(pipe);
// TODO (obastemur) remove negative return codes from the project
// then remove the below nonsense
if (*ec > 256 && *ec < 260) {
*ec = (*ec - 65536) / 256;
} else {
*ec = (*ec) >> 8;
}
// Only below line must be enough
// *ec = (*ec) >> 8;
#endif
// need checking ferror ?
#if defined(_WIN32)
*ec = _pclose(pipe);
#else
*ec = pclose(pipe);
*ec = (*ec) >> 8;
#endif
}

JS_METHOD(JXUtilsWrap, ExecSystem) {
Expand Down
2 changes: 1 addition & 1 deletion test/jxcore/test-exec-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ var child = cp.exec(cmd, {timeout: 10000}, function (error, stdout, stderr) {
console.log("error: " + error);
console.log("stdout: " + stdout);
console.log("stderr: " + stderr);
process.exit(-1);
process.exit(1);
}
});
2 changes: 1 addition & 1 deletion test/jxcore/test-monitor-kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var getJSON = function (cb) {

// ########################## jx monitor start
var ret = jxcore.utils.cmdSync(cmd + "start");
assert.strictEqual(ret.exitCode, -1, "Monitor did not start after `start` command. \n", JSON.stringify(ret));
assert.ok(ret.exitCode === 0, "Monitor did not start after `start` command. \n", JSON.stringify(ret));

// ########################## jx monitor run test-monitor-run-app.js

Expand Down
2 changes: 1 addition & 1 deletion test/jxcore/test-monitor-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var traceWin = function (cmd, res) {
// ########################## jx monitor start
var ret = jxcore.utils.cmdSync(cmd + "start");
traceWin(cmd + "start", ret);
assert.strictEqual(ret.exitCode, -1, "Monitor did not start after `start` command. \n", JSON.stringify(ret));
assert.ok(ret.exitCode === 0, "Monitor did not start after `start` command. \n", JSON.stringify(ret));

// ########################## jx monitor run test-monitor-run-app.js

Expand Down
2 changes: 1 addition & 1 deletion test/jxcore/test-node_path_start.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ if (ret.out.indexOf(mod.value2) === -1) {
console.log(cl('dir:') + ' `' + node_path + "`");
console.log(cl("command used:") + " \n" + cmd);
console.log(cl("output:"), ret.out, "\n\n");
process.exit(-1);
process.exit(1);
}
Loading

0 comments on commit 3bd08d9

Please sign in to comment.