File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,14 @@ describe('getConvertedFilePath', () => {
66
77 expect ( getConvertedFilePath ( logsString ) ) . toEqual ( '/tmp/test.docx' ) ;
88 } ) ;
9+
10+ it ( 'should throw extended error message when passed incorrect format string' , ( ) => {
11+ const logsString = 'log string that produces error' ;
12+
13+ expect ( ( ) => getConvertedFilePath ( logsString ) ) . toThrow (
14+ new TypeError (
15+ `TypeError: Cannot read properties of null (reading '1');\tTried to parse string: "log string that produces error"`
16+ )
17+ ) ;
18+ } ) ;
919} ) ;
Original file line number Diff line number Diff line change 11export function getConvertedFilePath ( logs : string ) : string {
2- return logs . match ( / \/ t m p \/ .+ - > \s ( \/ t m p \/ .+ ) u s i n g / ) [ 1 ] ;
2+ try {
3+ return logs . match ( / \/ t m p \/ .+ - > \s ( \/ t m p \/ .+ ) u s i n g / ) [ 1 ] ;
4+ } catch ( e ) {
5+ const ErrorWithExtendedMessage : Error = new Error ( e ) ;
6+ ErrorWithExtendedMessage . message += `;\tTried to parse string: "${ logs } "` ;
7+
8+ throw ErrorWithExtendedMessage ;
9+ }
310}
You can’t perform that action at this time.
0 commit comments