11import { env , EventEmitter } from "vscode" ;
22import { getVariantAnalysis } from "./gh-api/gh-api-client" ;
3+ import { RequestError } from "@octokit/request-error" ;
34
45import {
56 isFinalVariantAnalysisStatus ,
@@ -59,6 +60,12 @@ export class VariantAnalysisMonitor extends DisposableObject {
5960 private async _monitorVariantAnalysis (
6061 variantAnalysis : VariantAnalysis ,
6162 ) : Promise < void > {
63+ const variantAnalysisLabel = `${ variantAnalysis . query . name } (${
64+ variantAnalysis . query . language
65+ } ) [${ new Date ( variantAnalysis . executionStartTime ) . toLocaleString (
66+ env . language ,
67+ ) } ]`;
68+
6269 let attemptCount = 0 ;
6370 const scannedReposDownloaded : number [ ] = [ ] ;
6471
@@ -81,11 +88,7 @@ export class VariantAnalysisMonitor extends DisposableObject {
8188 } catch ( e ) {
8289 const errorMessage = getErrorMessage ( e ) ;
8390
84- const message = `Error while monitoring variant analysis ${
85- variantAnalysis . query . name
86- } (${ variantAnalysis . query . language } ) [${ new Date (
87- variantAnalysis . executionStartTime ,
88- ) . toLocaleString ( env . language ) } ]: ${ errorMessage } `;
91+ const message = `Error while monitoring variant analysis ${ variantAnalysisLabel } : ${ errorMessage } ` ;
8992
9093 // If we have already shown this error to the user, don't show it again.
9194 if ( lastErrorShown === errorMessage ) {
@@ -95,6 +98,19 @@ export class VariantAnalysisMonitor extends DisposableObject {
9598 lastErrorShown = errorMessage ;
9699 }
97100
101+ if ( e instanceof RequestError && e . status === 404 ) {
102+ // We want to show the error message to the user, but we don't want to
103+ // keep polling for the variant analysis if it no longer exists.
104+ // Therefore, this block is down here rather than at the top of the
105+ // catch block.
106+ void extLogger . log (
107+ `Variant analysis ${ variantAnalysisLabel } no longer exists or is no longer accessible, stopping monitoring.` ,
108+ ) ;
109+ // Cancel monitoring on 404, as this probably means the user does not have access to it anymore
110+ // e.g. lost access to repo, or repo was deleted
111+ return ;
112+ }
113+
98114 continue ;
99115 }
100116
0 commit comments