Skip to content

Commit

Permalink
chore(appium): Improve the error message on config load error (#18829)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jun 30, 2023
1 parent cb14587 commit 97fe159
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/appium/lib/config-file.js
Expand Up @@ -9,7 +9,11 @@ import {getSchema, validate} from './schema/schema';
* @type {import('lilconfig').LoaderSync}
*/
function yamlLoader(filepath, content) {
return yaml.parse(content);
try {
return yaml.parse(content);
} catch (e) {
throw new Error(`The YAML config at '${filepath}' cannot be loaded. Original error: ${e.message}`);
}
}

/**
Expand All @@ -27,7 +31,11 @@ const rawConfig = new Map();
*/
function jsonLoader(filepath, content) {
rawConfig.set(filepath, content);
return JSON.parse(content);
try {
return JSON.parse(content);
} catch (e) {
throw new Error(`The JSON config at '${filepath}' cannot be loaded. Original error: ${e.message}`);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/appium/test/e2e/config-file.e2e.spec.js
Expand Up @@ -320,7 +320,7 @@ describe('config file behavior', function () {
return this.skip();
}
await readConfigFile(INVALID_JSON_FILEPATH).should.be.rejectedWith(
new RegExp(`${INVALID_JSON_FILEPATH} is invalid`)
new RegExp(`${_.escapeRegExp(INVALID_JSON_FILEPATH)}`)
);
});
});
Expand Down

0 comments on commit 97fe159

Please sign in to comment.