Metadata
- Source
- KETTLE-75
- Type
- Bug
- Priority
- Major
- Status
- Resolved
- Resolution
- Fixed
- Assignee
- Antranig Basman
- Reporter
- Antranig Basman
- Created
2019-01-30T06:06:57.180-0500 - Updated
2019-02-04T18:45:04.610-0500 - Versions
- N/A
- Fixed Versions
- N/A
- Component
- N/A
Description
Kettle strategy for grabbing command-line arguments willy-nilly makes it impossible to start up applications in some cases if additional arguments are being passed to node.exe or electron.exe.
For example, attempting to start up gpii-app via electron --inspect-brk main.js gives a failure on startup as the filename argument gets interpreted as the config directory via the following code in KettleConfigName:
kettle.config.getConfigPath = function (outerDefault) {
var arg2 = process.argv[2];
if (arg2 === "-") {
arg2 = null;
}
var configPath = arg2 || outerDefault;
It seems there was some ancient attempt here to allow the skipping of some arguments. We should replace this with a scheme which shows some better sense of the argument structure and can skip everything until it finds the filename, and/or only recognise named arguments, or perhaps even abolish this scheme altogether.
At the time of the call, the process arguments are [V:\node_modules\electron\dist\electron.exe, --inspect-brk, main.js]
The failure we get is:
App threw an error during load
Error: Assertion failure - check console for more details: Could not find a config file at any of the paths V:\main.js\app.testing, V:\main.js\app.testing.json, V:\main.js\app.testing.json5
Comments
-
Antranig Basman commented
2019-01-30T10:54:30.904-0500 As a quick "hot patch" to allow people to use, e.g. --inspect-brk by hot-editing kettle from inside node_modules, this set of changes will simply disable Kettle's command-line parsing:
diff --git a/lib/KettleConfigLoader.js b/lib/KettleConfigLoader.js index 6a36abb..6d203ba 100644 --- a/lib/KettleConfigLoader.js +++ b/lib/KettleConfigLoader.js @@ -28,7 +28,8 @@ fluid.defaults("kettle.config", { * is suitable for appearing as the configName field in the options to <code>kettle.config.createDefaults</code> etc. */ kettle.config.getConfigName = function (outerDefault) { - var nodeEnv = process.argv[3] || process.env.NODE_ENV || outerDefault; + console.log("Process arguments are " + process.argv); + var nodeEnv = process.env.NODE_ENV || outerDefault; if (nodeEnv) { fluid.log("Loader running configuration name " + nodeEnv); } else { @@ -42,10 +43,7 @@ kettle.config.getConfigName = function (outerDefault) { * is suitable for appearing as the configPath field in the options to <code>kettle.config.createDefaults</code> etc. */ kettle.config.getConfigPath = function (outerDefault) { - var arg2 = process.argv[2]; - if (arg2 === "-") { - arg2 = null; - } + var arg2 = null; var configPath = arg2 || outerDefault; if (!configPath) { fluid.fail("Config path must be specified as 1st command line argument");
-
Antranig Basman commented
2019-02-04T06:59:40.077-0500 Note that this is more specifically a problem with executing electron apps from the command line. There is a long-standing fault in electron argument parsing which fails to strip off the V8-specific arguments which precede the script filename which is intended to appear in process.argv[1]. https://github.com/electron/electron/issues/4690 - this stackExchange answer explains the distinction between process.argv and process.execArgv which is observed in plain node but not with electron - https://stackoverflow.com/questions/4351521/how-do-i-pass-command-line-arguments-to-a-node-js-program#comment57056011_4351548