@@ -24,13 +24,29 @@ import * as util from "./util";
2424import { ConfigurationError , getErrorMessage , isDefined } from "./util" ;
2525
2626/**
27- * Enumerates specific error types, along with suitable error messages, for errors
28- * that we want to track in status reports.
27+ * Enumerates specific error types for which we have corresponding error messages that
28+ * are safe to include in status reports.
2929 */
3030export enum StartProxyErrorType {
31- DownloadFailed = "Failed to download proxy archive." ,
32- ExtractionFailed = "Failed to extract proxy archive." ,
33- CacheFailed = "Failed to add proxy to toolcache" ,
31+ DownloadFailed ,
32+ ExtractionFailed ,
33+ CacheFailed ,
34+ }
35+
36+ /**
37+ * @returns The error message corresponding to the error type.
38+ */
39+ export function getStartProxyErrorMessage (
40+ errorType : StartProxyErrorType ,
41+ ) : string {
42+ switch ( errorType ) {
43+ case StartProxyErrorType . DownloadFailed :
44+ return "Failed to download proxy archive." ;
45+ case StartProxyErrorType . ExtractionFailed :
46+ return "Failed to extract proxy archive." ;
47+ case StartProxyErrorType . CacheFailed :
48+ return "Failed to add proxy to toolcache" ;
49+ }
3450}
3551
3652/**
@@ -40,8 +56,11 @@ export enum StartProxyErrorType {
4056 * `StartProxyErrorType` and therefore safe to include in a status report.
4157 */
4258export class StartProxyError extends Error {
59+ public readonly errorType : StartProxyErrorType ;
60+
4361 constructor ( errorType : StartProxyErrorType ) {
44- super ( errorType ) ;
62+ super ( ) ;
63+ this . errorType = errorType ;
4564 }
4665}
4766
@@ -89,10 +108,10 @@ export async function sendSuccessStatusReport(
89108 * @param error The error for which to get an error message.
90109 */
91110export function getSafeErrorMessage ( error : Error ) : string {
92- // If the error is a `StartProxyError`, the constructor ensures that the
93- // message comes from `StartProxyErrorType` .
111+ // If the error is a `StartProxyError`, resolve the error type to the corresponding
112+ // error message .
94113 if ( error instanceof StartProxyError ) {
95- return error . message ;
114+ return getStartProxyErrorMessage ( error . errorType ) ;
96115 }
97116
98117 // Otherwise, omit the actual error message.
0 commit comments