Skip to content

Commit

Permalink
Fix another "cannot read property of undefined" error (#1354)
Browse files Browse the repository at this point in the history
* Fix reading undefined reference when there are no existing pull requests to update yet

* Improved logging to ensure error stack traces are always dumped; helps with debugging
  • Loading branch information
rhyskoedijk authored Sep 25, 2024
1 parent 04eb4ad commit 109443c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
38 changes: 20 additions & 18 deletions extension/tasks/dependabotV2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'`);
}
}

Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 [];
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 109443c

Please sign in to comment.