From 4c8d0635dfd18e4195e7dcc91c932d69344f2958 Mon Sep 17 00:00:00 2001 From: Adrian Zhang Date: Fri, 3 May 2024 20:13:26 +0800 Subject: [PATCH 1/3] chore: Provide the filename of the package.json file where the error occurred --- ...re-error-packageJSON-filename_2024-05-03-12-11.json | 10 ++++++++++ libraries/rush-lib/src/api/RushConfigurationProject.ts | 5 +++++ 2 files changed, 15 insertions(+) create mode 100644 common/changes/@microsoft/rush/chore-error-packageJSON-filename_2024-05-03-12-11.json diff --git a/common/changes/@microsoft/rush/chore-error-packageJSON-filename_2024-05-03-12-11.json b/common/changes/@microsoft/rush/chore-error-packageJSON-filename_2024-05-03-12-11.json new file mode 100644 index 00000000000..96822bb931d --- /dev/null +++ b/common/changes/@microsoft/rush/chore-error-packageJSON-filename_2024-05-03-12-11.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Provide the filename of the error package.json file", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/api/RushConfigurationProject.ts b/libraries/rush-lib/src/api/RushConfigurationProject.ts index d8b3b999608..6399bae631e 100644 --- a/libraries/rush-lib/src/api/RushConfigurationProject.ts +++ b/libraries/rush-lib/src/api/RushConfigurationProject.ts @@ -245,6 +245,11 @@ export class RushConfigurationProject { if (FileSystem.isNotExistError(error as Error)) { throw new Error(`Could not find package.json for ${packageName} at ${packageJsonFilename}`); } + + // Encountered an error while loading the package.json file. Please append the error message with the corresponding file location. + if ((error as Error).name === 'SyntaxError') { + error.message = `${error.message}\nFilename: ${packageJsonFilename}`; + } throw error; } From 14e3891dc38d802e96b20025367d2d562efdaa14 Mon Sep 17 00:00:00 2001 From: Adrian Zhang Date: Sat, 4 May 2024 09:03:09 +0800 Subject: [PATCH 2/3] Update chore-error-packageJSON-filename_2024-05-03-12-11.json Co-authored-by: Ian Clanton-Thuon --- .../rush/chore-error-packageJSON-filename_2024-05-03-12-11.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/changes/@microsoft/rush/chore-error-packageJSON-filename_2024-05-03-12-11.json b/common/changes/@microsoft/rush/chore-error-packageJSON-filename_2024-05-03-12-11.json index 96822bb931d..6bc32266ff0 100644 --- a/common/changes/@microsoft/rush/chore-error-packageJSON-filename_2024-05-03-12-11.json +++ b/common/changes/@microsoft/rush/chore-error-packageJSON-filename_2024-05-03-12-11.json @@ -2,7 +2,7 @@ "changes": [ { "packageName": "@microsoft/rush", - "comment": "Provide the filename of the error package.json file", + "comment": "Provide the file path if there is an error parsing a `package.json` file.", "type": "none" } ], From 5eb1a2bf30b87e72c554fdbc5ea2430c7a2b22f5 Mon Sep 17 00:00:00 2001 From: Adrian Zhang Date: Sun, 5 May 2024 11:23:24 +0800 Subject: [PATCH 3/3] Update RushConfigurationProject.ts Co-authored-by: Ian Clanton-Thuon --- libraries/rush-lib/src/api/RushConfigurationProject.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/rush-lib/src/api/RushConfigurationProject.ts b/libraries/rush-lib/src/api/RushConfigurationProject.ts index 6399bae631e..dabf9f19679 100644 --- a/libraries/rush-lib/src/api/RushConfigurationProject.ts +++ b/libraries/rush-lib/src/api/RushConfigurationProject.ts @@ -247,7 +247,7 @@ export class RushConfigurationProject { } // Encountered an error while loading the package.json file. Please append the error message with the corresponding file location. - if ((error as Error).name === 'SyntaxError') { + if (error instanceof SyntaxError) { error.message = `${error.message}\nFilename: ${packageJsonFilename}`; } throw error;