Skip to content

Commit

Permalink
feat: throw error with log string when trying to getCovertedFilePath
Browse files Browse the repository at this point in the history
  • Loading branch information
Siloss committed Aug 11, 2022
1 parent 28e1232 commit f144eee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ describe('getConvertedFilePath', () => {

expect(getConvertedFilePath(logsString)).toEqual('/tmp/test.docx');
});

it('should throw extended error message when passed incorrect format string', () => {
const logsString = 'log string that produces error';

expect(() => getConvertedFilePath(logsString)).toThrow(
new TypeError(
`TypeError: Cannot read properties of null (reading '1');\tTried to parse string: "log string that produces error"`
)
);
});
});
9 changes: 8 additions & 1 deletion src/logs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export function getConvertedFilePath(logs: string): string {
return logs.match(/\/tmp\/.+->\s(\/tmp\/.+) using/)[1];
try {
return logs.match(/\/tmp\/.+->\s(\/tmp\/.+) using/)[1];
} catch (e) {
const ErrorWithExtendedMessage: Error = new Error(e);
ErrorWithExtendedMessage.message += `;\tTried to parse string: "${logs}"`;

throw ErrorWithExtendedMessage;
}
}

0 comments on commit f144eee

Please sign in to comment.