From 8fa3acfd80678d9c2f68573d487cb3356e9aad1c Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 13 May 2024 14:40:05 +0200 Subject: [PATCH] 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 --- ghost/package-json/lib/parse.js | 35 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/ghost/package-json/lib/parse.js b/ghost/package-json/lib/parse.js index 0a81a081fe..08fd235ded 100644 --- a/ghost/package-json/lib/parse.js +++ b/ghost/package-json/lib/parse.js @@ -23,35 +23,32 @@ async function parse(path) { try { source = await fs.readFile(path, {encoding: 'utf8'}); } catch (readError) { - const err = new errors.IncorrectUsageError(); - err.message = tpl(messages.couldNotReadPackage); - err.context = path; - err.err = readError; - - return Promise.reject(err); + throw new errors.IncorrectUsageError({ + message: tpl(messages.couldNotReadPackage), + context: path, + err: readError + }); } try { json = JSON.parse(source); } catch (parseError) { - const err = new errors.IncorrectUsageError(); - err.message = tpl(messages.themeFileIsMalformed); - err.context = path; - err.err = parseError; - err.help = tpl(messages.willBeRequired, {url: 'https://ghost.org/docs/themes/'}); - - return Promise.reject(err); + throw new errors.IncorrectUsageError({ + message: tpl(messages.themeFileIsMalformed), + context: path, + err: parseError, + help: tpl(messages.willBeRequired, {url: 'https://ghost.org/docs/themes/'}) + }); } const hasRequiredKeys = json.name && json.version; if (!hasRequiredKeys) { - const err = new errors.IncorrectUsageError(); - err.message = tpl(messages.nameOrVersionMissing); - err.context = path; - err.help = tpl(messages.willBeRequired, {url: 'https://ghost.org/docs/themes/'}); - - return Promise.reject(err); + throw new errors.IncorrectUsageError({ + message: tpl(messages.nameOrVersionMissing), + context: path, + help: tpl(messages.willBeRequired, {url: 'https://ghost.org/docs/themes/'}) + }); } return json;