Fixed providing err
to IncorrectUsageError
- it appears as though we only accept `err` when it's in the constructor of the IncorrectUsageError, so in its current form, it is ignored - this commit performs a minor refactor to switch to constructing a new IncorrectUsageError and then throwing it - detected by tsserver complaining about the `err` property not existing on the error
This commit is contained in:
parent
cb8213e7d3
commit
8fa3acfd80
@ -23,35 +23,32 @@ async function parse(path) {
|
|||||||
try {
|
try {
|
||||||
source = await fs.readFile(path, {encoding: 'utf8'});
|
source = await fs.readFile(path, {encoding: 'utf8'});
|
||||||
} catch (readError) {
|
} catch (readError) {
|
||||||
const err = new errors.IncorrectUsageError();
|
throw new errors.IncorrectUsageError({
|
||||||
err.message = tpl(messages.couldNotReadPackage);
|
message: tpl(messages.couldNotReadPackage),
|
||||||
err.context = path;
|
context: path,
|
||||||
err.err = readError;
|
err: readError
|
||||||
|
});
|
||||||
return Promise.reject(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(source);
|
json = JSON.parse(source);
|
||||||
} catch (parseError) {
|
} catch (parseError) {
|
||||||
const err = new errors.IncorrectUsageError();
|
throw new errors.IncorrectUsageError({
|
||||||
err.message = tpl(messages.themeFileIsMalformed);
|
message: tpl(messages.themeFileIsMalformed),
|
||||||
err.context = path;
|
context: path,
|
||||||
err.err = parseError;
|
err: parseError,
|
||||||
err.help = tpl(messages.willBeRequired, {url: 'https://ghost.org/docs/themes/'});
|
help: tpl(messages.willBeRequired, {url: 'https://ghost.org/docs/themes/'})
|
||||||
|
});
|
||||||
return Promise.reject(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasRequiredKeys = json.name && json.version;
|
const hasRequiredKeys = json.name && json.version;
|
||||||
|
|
||||||
if (!hasRequiredKeys) {
|
if (!hasRequiredKeys) {
|
||||||
const err = new errors.IncorrectUsageError();
|
throw new errors.IncorrectUsageError({
|
||||||
err.message = tpl(messages.nameOrVersionMissing);
|
message: tpl(messages.nameOrVersionMissing),
|
||||||
err.context = path;
|
context: path,
|
||||||
err.help = tpl(messages.willBeRequired, {url: 'https://ghost.org/docs/themes/'});
|
help: tpl(messages.willBeRequired, {url: 'https://ghost.org/docs/themes/'})
|
||||||
|
});
|
||||||
return Promise.reject(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
|
Loading…
Reference in New Issue
Block a user