Skip to content

Commit ee79e87

Browse files
committed
addressed comments
1 parent 0a5dfdf commit ee79e87

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

commands/utils/set_args.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ function write_file(file_path, content) {
1717
function sync_args_from_cmd(args) {
1818
return new Promise(function (resolve, reject) {
1919
let rawdata = fs.readFileSync(args["lambdatest-config-file"]);
20-
let lt_config = JSON.parse(rawdata);
20+
let lt_config;
21+
try {
22+
lt_config = JSON.parse(rawdata);
23+
} catch (err) {
24+
reject("error in parsing lambdatest-config-file",err);
25+
}
2126
let usernameFromEnvFile = undefined;
2227
let accessKeyFromEnvFile = undefined;
2328
let envFile,parsedEnv;
2429
let dot_env_vars = undefined;
30+
let dot_env_keys_list = undefined;
2531
let envFilePath = path.join(".", `.env`);
2632
if ("sys-env-keys" in args) {
2733
dot_env_vars = args["sys-env-keys"];
@@ -30,18 +36,18 @@ function sync_args_from_cmd(args) {
3036
}
3137
if (dot_env_vars) {
3238
dot_env_vars = dot_env_vars.trim();
33-
dot_env_vars = dot_env_vars.split(",");
39+
dot_env_keys_list = dot_env_vars.split(",");
3440
if ("envfl" in args) {
3541
envFilePath = args["envfl"];
36-
} else if (lt_config["run_settings"]["env_file"]) {
42+
} else if (lt_config["run_settings"] && lt_config["run_settings"]["env_file"]) {
3743
envFilePath = lt_config["run_settings"]["env_file"];
3844
}
3945

4046
try {
4147
envFile = fs.readFileSync(envFilePath, {encoding: 'utf8'})
4248
parsedEnv = dotenv.parse(envFile)
43-
for (index in dot_env_vars) {
44-
let envKey = dot_env_vars[index]
49+
for (index in dot_env_keys_list) {
50+
let envKey = dot_env_keys_list[index]
4551
if (envKey==constants.LT_USERNAME_ENV){
4652
let envValue = parsedEnv[envKey]
4753
if (envValue){
@@ -451,10 +457,10 @@ function sync_args_from_cmd(args) {
451457
}
452458
}
453459

454-
if (dot_env_vars) {
460+
if (dot_env_keys_list) {
455461
try {
456-
for (index in dot_env_vars) {
457-
let envKey = dot_env_vars[index]
462+
for (index in dot_env_keys_list) {
463+
let envKey = dot_env_keys_list[index]
458464
let envValue = parsedEnv[envKey]
459465
envs[envKey] = envValue
460466
}

0 commit comments

Comments
 (0)