@@ -19,57 +19,91 @@ import {
1919 setupTests ,
2020 withRecordingLoggerAsync ,
2121} from "./testing-utils" ;
22+ import { ConfigurationError } from "./util" ;
2223
2324setupTests ( test ) ;
2425
25- test ( "sendFailedStatusReport - does not report messages from arbitrary error types" , async ( t ) => {
26- const loggedMessages = [ ] ;
27- const logger = getRecordingLogger ( loggedMessages ) ;
28- const error = new Error (
26+ const sendFailedStatusReportTest = test . macro ( {
27+ exec : async (
28+ t : ExecutionContext < unknown > ,
29+ err : Error ,
30+ expectedMessage : string ,
31+ expectedStatus : statusReport . ActionStatus = "failure" ,
32+ ) => {
33+ const now = new Date ( ) ;
34+
35+ // Override core.setFailed to avoid it setting the program's exit code
36+ sinon . stub ( core , "setFailed" ) . returns ( ) ;
37+
38+ const createStatusReportBase = sinon . stub (
39+ statusReport ,
40+ "createStatusReportBase" ,
41+ ) ;
42+ createStatusReportBase . resolves ( undefined ) ;
43+
44+ await withRecordingLoggerAsync ( async ( logger ) => {
45+ await startProxyExports . sendFailedStatusReport (
46+ logger ,
47+ now ,
48+ undefined ,
49+ err ,
50+ ) ;
51+
52+ // Check that the stub has been called exactly once, with the expected arguments,
53+ // but not with the message from the error.
54+ sinon . assert . calledOnceWithExactly (
55+ createStatusReportBase ,
56+ statusReport . ActionName . StartProxy ,
57+ expectedStatus ,
58+ now ,
59+ sinon . match . any ,
60+ sinon . match . any ,
61+ sinon . match . any ,
62+ expectedMessage ,
63+ ) ;
64+ t . false (
65+ createStatusReportBase . calledWith (
66+ statusReport . ActionName . StartProxy ,
67+ expectedStatus ,
68+ now ,
69+ sinon . match . any ,
70+ sinon . match . any ,
71+ sinon . match . any ,
72+ sinon . match ( ( msg : string ) => msg . includes ( err . message ) ) ,
73+ ) ,
74+ "createStatusReportBase was called with the error message" ,
75+ ) ;
76+ } ) ;
77+ } ,
78+
79+ title : ( providedTitle = "" ) => `sendFailedStatusReport - ${ providedTitle } ` ,
80+ } ) ;
81+
82+ test (
83+ "reports generic error message for non-StartProxyError error" ,
84+ sendFailedStatusReportTest ,
85+ new Error ( "Something went wrong today" ) ,
86+ "Error from start-proxy Action omitted (Error)." ,
87+ ) ;
88+
89+ test (
90+ "reports generic error message for non-StartProxyError error with safe error message" ,
91+ sendFailedStatusReportTest ,
92+ new Error (
2993 startProxyExports . getStartProxyErrorMessage (
3094 startProxyExports . StartProxyErrorType . DownloadFailed ,
3195 ) ,
32- ) ;
33- const now = new Date ( ) ;
34-
35- // Override core.setFailed to avoid it setting the program's exit code
36- sinon . stub ( core , "setFailed" ) . returns ( ) ;
96+ ) ,
97+ "Error from start-proxy Action omitted (Error)." ,
98+ ) ;
3799
38- const createStatusReportBase = sinon . stub (
39- statusReport ,
40- "createStatusReportBase" ,
41- ) ;
42- createStatusReportBase . resolves ( undefined ) ;
43-
44- await startProxyExports . sendFailedStatusReport ( logger , now , undefined , error ) ;
45-
46- // Check that the stub has been called exactly once, with the expected arguments,
47- // but not with the message from the error.
48- t . assert ( createStatusReportBase . calledOnce ) ;
49- t . assert (
50- createStatusReportBase . calledWith (
51- statusReport . ActionName . StartProxy ,
52- "failure" ,
53- now ,
54- sinon . match . any ,
55- sinon . match . any ,
56- sinon . match . any ,
57- ) ,
58- "createStatusReportBase wasn't called with the expected arguments" ,
59- ) ;
60- t . false (
61- createStatusReportBase . calledWith (
62- statusReport . ActionName . StartProxy ,
63- "failure" ,
64- now ,
65- sinon . match . any ,
66- sinon . match . any ,
67- sinon . match . any ,
68- sinon . match ( ( msg : string ) => msg . includes ( error . message ) ) ,
69- ) ,
70- "createStatusReportBase was called with the error message" ,
71- ) ;
72- } ) ;
100+ test (
101+ "reports generic error message for ConfigurationError error" ,
102+ sendFailedStatusReportTest ,
103+ new ConfigurationError ( "Something went wrong today" ) ,
104+ "Error from start-proxy Action omitted (ConfigurationError)." ,
105+ "user-error" ,
106+ ) ;
73107
74108const toEncodedJSON = ( data : any ) =>
75109 Buffer . from ( JSON . stringify ( data ) ) . toString ( "base64" ) ;
@@ -395,7 +429,7 @@ test("getSafeErrorMessage - does not return message for arbitrary errors", (t) =
395429
396430 t . not ( message , error . message ) ;
397431 t . assert ( message . startsWith ( "Error from start-proxy Action omitted" ) ) ;
398- t . assert ( message . includes ( typeof error ) ) ;
432+ t . assert ( message . includes ( error . name ) ) ;
399433} ) ;
400434
401435const wrapFailureTest = test . macro ( {
0 commit comments