From 529eb9497f51dd873c2397eef1c5de70d6d80feb Mon Sep 17 00:00:00 2001 From: Rhys Koedijk Date: Tue, 24 Sep 2024 17:26:17 +1200 Subject: [PATCH 1/2] Fix reading undefined reference when there are no existing pull requests to update yet --- extension/tasks/dependabotV2/index.ts | 38 ++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/extension/tasks/dependabotV2/index.ts b/extension/tasks/dependabotV2/index.ts index d9811c2c..b1ee6025 100644 --- a/extension/tasks/dependabotV2/index.ts +++ b/extension/tasks/dependabotV2/index.ts @@ -111,25 +111,27 @@ async function run() { failedJobs++; } - // Run an update job for each existing pull request; this will resolve merge conflicts and close pull requests that are no longer needed - if (!taskInputs.skipPullRequests) { - for (const pullRequestId in existingPullRequests) { - const updatePullRequestJob = DependabotJobBuilder.newUpdatePullRequestJob( - taskInputs, - pullRequestId, - update, - dependabotConfig.registries, - existingPullRequestDependencies, - existingPullRequests[pullRequestId], - ); - const updatePullRequestOutputs = await dependabot.update(updatePullRequestJob, dependabotUpdaterOptions); - if (!updatePullRequestOutputs || updatePullRequestOutputs.filter((u) => !u.success).length > 0) { - updatePullRequestOutputs.filter((u) => !u.success).forEach((u) => exception(u.error)); - failedJobs++; + // If there are existing pull requests, run an update job for each one; this will resolve merge conflicts and close pull requests that are no longer needed + if (existingPullRequests && existingPullRequests.keys.length > 0) { + if (!taskInputs.skipPullRequests) { + for (const pullRequestId in existingPullRequests) { + const updatePullRequestJob = DependabotJobBuilder.newUpdatePullRequestJob( + taskInputs, + pullRequestId, + update, + dependabotConfig.registries, + existingPullRequestDependencies, + existingPullRequests[pullRequestId], + ); + const updatePullRequestOutputs = await dependabot.update(updatePullRequestJob, dependabotUpdaterOptions); + if (!updatePullRequestOutputs || updatePullRequestOutputs.filter((u) => !u.success).length > 0) { + updatePullRequestOutputs.filter((u) => !u.success).forEach((u) => exception(u.error)); + failedJobs++; + } } + } else { + warning(`Skipping update of existing pull requests as 'skipPullRequests' is set to 'true'`); } - } else if (existingPullRequests.keys.length > 0) { - warning(`Skipping update of existing pull requests as 'skipPullRequests' is set to 'true'`); } } @@ -150,7 +152,7 @@ async function run() { function exception(e: Error) { if (e) { error(`An unhandled exception occurred: ${e}`); - console.error(e); + console.debug(e); // Dump the stack trace to help with debugging } } From c61b8b02f4143ab6b79b9c149e8e9dad4cae5dee Mon Sep 17 00:00:00 2001 From: Rhys Koedijk Date: Tue, 24 Sep 2024 17:26:50 +1200 Subject: [PATCH 2/2] Improved logging to ensure error stack traces are always dumped; helps with debugging --- .../azure-devops/AzureDevOpsWebApiClient.ts | 16 ++++++++-------- .../dependabot-cli/DependabotOutputProcessor.ts | 6 ++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/extension/tasks/dependabotV2/utils/azure-devops/AzureDevOpsWebApiClient.ts b/extension/tasks/dependabotV2/utils/azure-devops/AzureDevOpsWebApiClient.ts index 7091661e..95e9e5d9 100644 --- a/extension/tasks/dependabotV2/utils/azure-devops/AzureDevOpsWebApiClient.ts +++ b/extension/tasks/dependabotV2/utils/azure-devops/AzureDevOpsWebApiClient.ts @@ -68,7 +68,7 @@ export class AzureDevOpsWebApiClient { return repo.defaultBranch; } catch (e) { error(`Failed to get default branch for '${project}/${repository}': ${e}`); - console.error(e); + console.debug(e); // Dump the error stack trace to help with debugging return undefined; } } @@ -114,7 +114,7 @@ export class AzureDevOpsWebApiClient { ); } catch (e) { error(`Failed to list active pull request properties: ${e}`); - console.error(e); + console.debug(e); // Dump the error stack trace to help with debugging return []; } } @@ -264,7 +264,7 @@ export class AzureDevOpsWebApiClient { return pullRequest.pullRequestId; } catch (e) { error(`Failed to create pull request: ${e}`); - console.error(e); + console.debug(e); // Dump the error stack trace to help with debugging return null; } } @@ -348,7 +348,7 @@ export class AzureDevOpsWebApiClient { return true; } catch (e) { error(`Failed to update pull request: ${e}`); - console.error(e); + console.debug(e); // Dump the error stack trace to help with debugging return false; } } @@ -384,7 +384,7 @@ export class AzureDevOpsWebApiClient { console.info(` - Pull request #${options.pullRequestId} was approved.`); } catch (e) { error(`Failed to approve pull request: ${e}`); - console.error(e); + console.debug(e); // Dump the error stack trace to help with debugging return false; } } @@ -462,7 +462,7 @@ export class AzureDevOpsWebApiClient { return true; } catch (e) { error(`Failed to close pull request: ${e}`); - console.error(e); + console.debug(e); // Dump the error stack trace to help with debugging return false; } } @@ -482,7 +482,7 @@ export class AzureDevOpsWebApiClient { return properties.map((p) => ({ [p.name]: p.value })).reduce((a, b) => ({ ...a, ...b }), {}); } catch (e) { error(`Failed to get project properties: ${e}`); - console.error(e); + console.debug(e); // Dump the error stack trace to help with debugging return undefined; } } @@ -517,7 +517,7 @@ export class AzureDevOpsWebApiClient { ]); } catch (e) { error(`Failed to update project property '${name}': ${e}`); - console.error(e); + console.debug(e); // Dump the error stack trace to help with debugging } } } diff --git a/extension/tasks/dependabotV2/utils/dependabot-cli/DependabotOutputProcessor.ts b/extension/tasks/dependabotV2/utils/dependabot-cli/DependabotOutputProcessor.ts index d5571519..5ffb958d 100644 --- a/extension/tasks/dependabotV2/utils/dependabot-cli/DependabotOutputProcessor.ts +++ b/extension/tasks/dependabotV2/utils/dependabot-cli/DependabotOutputProcessor.ts @@ -224,13 +224,11 @@ export class DependabotOutputProcessor implements IDependabotUpdateOutputProcess break; case 'record_update_job_error': - error(`Update job error: ${data['error-type']}`); - console.log(data['error-details']); + error(`Update job error: ${data['error-type']} ${JSON.stringify(data['error-details'])}`); return false; case 'record_update_job_unknown_error': - error(`Update job unknown error: ${data['error-type']}`); - console.log(data['error-details']); + error(`Update job unknown error: ${data['error-type']}, ${JSON.stringify(data['error-details'])}`); return false; case 'increment_metric':