@@ -232,7 +232,7 @@ export abstract class DotnetTool implements IDotnetTool {
232232 const result = await this . execute ( 'dotnet' , builder . build ( ) )
233233
234234 // Each line of the output starts with either E (enabled) or D (disabled), followed by a space and index url.
235- const nugetSources = [ ...( result . stdout ?? '' ) . matchAll ( / ^ E (?< index > .+ ) / gm) ] . map ( m => m . groups ! . index )
235+ const nugetSources = [ ...( result . stdout ?? '' ) . matchAll ( / ^ E (?< index > .+ ) / gm) ] . map ( m => m . groups ? .index ?? '' ) . filter ( s => ! ! s )
236236
237237 if ( ! nugetSources . length ) {
238238 this . buildAgent . error ( 'Failed to fetch an enabled package source for dotnet.' )
@@ -242,7 +242,10 @@ export abstract class DotnetTool implements IDotnetTool {
242242 const sources : string [ ] = [ ]
243243 for ( const nugetSource of nugetSources ) {
244244 // Fetch the nuget source index to obtain the query service
245- const nugetIndex = await fetch ( nugetSource )
245+ const nugetIndex = await fetch ( nugetSource ) . catch ( ( e : { cause : { message : string | undefined } | undefined } ) => {
246+ this . buildAgent . warn ( e . cause ?. message ?? 'An unknown error occurred while fetching data' )
247+ return Response . error ( )
248+ } )
246249 if ( ! nugetIndex ?. ok ) {
247250 this . buildAgent . warn ( `Failed to fetch data from NuGet source ${ nugetSource } .` )
248251 continue
@@ -262,21 +265,26 @@ export abstract class DotnetTool implements IDotnetTool {
262265 }
263266
264267 private async queryVersionsFromNugetSource ( serviceUrl : string , toolName : string , includePrerelease : boolean ) : Promise < string [ ] > {
268+ this . buildAgent . debug ( `Fetching ${ toolName } versions from source ${ serviceUrl } ` )
265269 const toolNameParam = encodeURIComponent ( toolName . toLowerCase ( ) )
266270 const prereleaseParam = includePrerelease ? 'true' : 'false'
267271 const downloadPath = `${ serviceUrl } ?q=${ toolNameParam } &prerelease=${ prereleaseParam } &semVerLevel=2.0.0&take=1`
268272
269- const response = await fetch ( downloadPath )
273+ const response = await fetch ( downloadPath ) . catch ( ( e : { cause : { message : string | undefined } | undefined } ) => {
274+ this . buildAgent . warn ( e . cause ?. message ?? 'An unknown error occurred while fetching data' )
275+ return Response . error ( )
276+ } )
270277
271278 if ( ! response || ! response . ok ) {
272279 this . buildAgent . warn ( `failed to query latest version for ${ toolName } from ${ downloadPath } . Status code: ${ response ? response . status : 'unknown' } ` )
273280 return [ ]
274281 }
275282 const { data } = ( await response . json ( ) ) as NugetVersions
276283
277- const versions = data [ 0 ] . versions . map ( x => x . version )
284+ const versions = data ?. [ 0 ] ? .versions ? .map ( x => x . version ) ?? [ ]
278285
279- return versions ?? [ ]
286+ this . buildAgent . debug ( `Found ${ versions . length } versions: ${ versions . join ( ', ' ) } ` )
287+ return versions
280288 }
281289
282290 private async queryLatestMatch ( toolName : string , versionSpec : string , includePrerelease : boolean ) : Promise < string | null > {
0 commit comments