Skip to content

Commit f144eee

Browse files
committed
feat: throw error with log string when trying to getCovertedFilePath
1 parent 28e1232 commit f144eee

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/logs.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

src/logs.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
export function getConvertedFilePath(logs: string): string {
2-
return logs.match(/\/tmp\/.+->\s(\/tmp\/.+) using/)[1];
2+
try {
3+
return logs.match(/\/tmp\/.+->\s(\/tmp\/.+) using/)[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
}

0 commit comments

Comments
 (0)