Skip to content

Commit 66a02ec

Browse files
authored
Better logging for fetching failed (#5992)
Part of #5990
1 parent 3cccf46 commit 66a02ec

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/github/githubRepository.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,12 @@ export class GitHubRepository implements vscode.Disposable {
539539
}
540540

541541
async getAllPullRequests(page?: number): Promise<PullRequestData | undefined> {
542+
let remote: GitHubRemote | undefined;
542543
try {
543544
Logger.debug(`Fetch all pull requests - enter`, GitHubRepository.ID);
544-
const { octokit, remote } = await this.ensure();
545+
const ensured = await this.ensure();
546+
remote = ensured.remote;
547+
const octokit = ensured.octokit;
545548
const result = await octokit.call(octokit.api.pulls.list, {
546549
owner: remote.owner,
547550
repo: remote.repositoryName,
@@ -585,7 +588,7 @@ export class GitHubRepository implements vscode.Disposable {
585588
if (e.code === 404) {
586589
// not found
587590
vscode.window.showWarningMessage(
588-
`Fetching pull requests for remote '${this.remote.remoteName}' failed, please check if the url ${this.remote.url} is valid.`,
591+
`Fetching all pull requests for remote '${remote?.remoteName}' failed, please check if the repository ${remote?.owner}/${remote?.repositoryName} is valid.`,
589592
);
590593
} else {
591594
throw e;
@@ -595,9 +598,12 @@ export class GitHubRepository implements vscode.Disposable {
595598
}
596599

597600
async getPullRequestForBranch(branch: string, headOwner: string): Promise<PullRequestModel | undefined> {
601+
let remote: GitHubRemote | undefined;
598602
try {
599603
Logger.debug(`Fetch pull requests for branch - enter`, GitHubRepository.ID);
600-
const { query, remote, schema } = await this.ensure();
604+
const ensured = await this.ensure();
605+
remote = ensured.remote;
606+
const { query, schema } = ensured;
601607
const { data } = await query<PullRequestsResponse>({
602608
query: schema.PullRequestForHead,
603609
variables: {
@@ -617,11 +623,11 @@ export class GitHubRepository implements vscode.Disposable {
617623
return this.createOrUpdatePullRequestModel(mostRecentOrOpenPr);
618624
}
619625
} catch (e) {
620-
Logger.error(`Fetching pull requests for branch failed: ${e}`, GitHubRepository.ID);
626+
Logger.error(`Fetching pull request for branch failed: ${e}`, GitHubRepository.ID);
621627
if (e.code === 404) {
622628
// not found
623629
vscode.window.showWarningMessage(
624-
`Fetching pull requests for remote '${this.remote.remoteName}' failed, please check if the url ${this.remote.url} is valid.`,
630+
`Fetching pull request for branch for remote '${remote?.remoteName}' failed, please check if the repository ${remote?.owner}/${remote?.repositoryName} is valid.`,
625631
);
626632
}
627633
}
@@ -866,13 +872,14 @@ export class GitHubRepository implements vscode.Disposable {
866872
}
867873

868874
async getPullRequestsForCategory(categoryQuery: string, page?: number): Promise<PullRequestData | undefined> {
875+
let repo: IMetadata | undefined;
869876
try {
870877
Logger.debug(`Fetch pull request category ${categoryQuery} - enter`, GitHubRepository.ID);
871878
const { octokit, query, schema } = await this.ensure();
872879

873880
const user = await this.getAuthenticatedUser();
874881
// Search api will not try to resolve repo that redirects, so get full name first
875-
const repo = await this.getMetadata();
882+
repo = await this.getMetadata();
876883
const { data, headers } = await octokit.call(octokit.api.search.issuesAndPullRequests, {
877884
q: getPRFetchQuery(repo.full_name, user, categoryQuery),
878885
per_page: PULL_REQUEST_PAGE_SIZE,
@@ -915,11 +922,11 @@ export class GitHubRepository implements vscode.Disposable {
915922
hasMorePages,
916923
};
917924
} catch (e) {
918-
Logger.error(`Fetching all pull requests failed: ${e}`, GitHubRepository.ID);
925+
Logger.error(`Fetching pull request with query failed: ${e}`, GitHubRepository.ID);
919926
if (e.code === 404) {
920927
// not found
921928
vscode.window.showWarningMessage(
922-
`Fetching pull requests for remote ${this.remote.remoteName}, please check if the url ${this.remote.url} is valid.`,
929+
`Fetching pull requests for remote ${this.remote.remoteName} with query failed, please check if the repo ${repo?.full_name} is valid.`,
923930
);
924931
} else {
925932
throw e;

0 commit comments

Comments
 (0)