From 3d475a0ddb91d5ebd85718a86aa02d340bf23fbb Mon Sep 17 00:00:00 2001 From: Isabel Tomb Date: Fri, 13 Dec 2024 16:23:15 -0600 Subject: [PATCH] Update condition before calling normalizeCodeOwner Update the condition in the ternary operator in the resolveCodeOwner function to check that match.owners isn't empty before calling normalizeCodeOwner with match.owners[0] Before this change normalizeCodeOwner could potentially throw an error during processing if the `match` object exists but the match.owners array is empty because normalizeCodeOwner will be passed `undefined` instead of the string it expects. Signed-off-by: Isabel Tomb --- .changeset/twenty-laws-tie.md | 5 +++++ plugins/catalog-backend/src/processors/codeowners/resolve.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/twenty-laws-tie.md diff --git a/.changeset/twenty-laws-tie.md b/.changeset/twenty-laws-tie.md new file mode 100644 index 0000000000..a1f9e88e57 --- /dev/null +++ b/.changeset/twenty-laws-tie.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Updated condition in resolveCodeOwner to fix a bug where normalizeCodeOwner could potentially be called with an invalid arg causing an error in CodeOwnersProcessor. diff --git a/plugins/catalog-backend/src/processors/codeowners/resolve.ts b/plugins/catalog-backend/src/processors/codeowners/resolve.ts index 675f6542aa..b0c44a8797 100644 --- a/plugins/catalog-backend/src/processors/codeowners/resolve.ts +++ b/plugins/catalog-backend/src/processors/codeowners/resolve.ts @@ -30,7 +30,9 @@ export function resolveCodeOwner( const { filepath } = parseGitUrl(catalogInfoFileUrl); const match = codeowners.matchFile(filepath, codeOwnerEntries); - return match ? normalizeCodeOwner(match.owners[0]) : undefined; + return match?.owners?.length + ? normalizeCodeOwner(match.owners[0]) + : undefined; } export function normalizeCodeOwner(owner: string) {