Skip to content

Commit 96c1248

Browse files
committed
feat: LOAPI-19 rethrow via stderr
1 parent 3c42871 commit 96c1248

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/convert.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,21 @@ export async function convertTo(filename: string, format: string): Promise<strin
2828

2929
// due to an unknown issue, we need to run command twice
3030
try {
31-
logs = (await exec(cmd)).stdout;
31+
const {stdout, stderr} = await exec(cmd);
32+
logs = stdout || new Error(stderr);
3233
} catch (e) {
33-
logs = (await exec(cmd)).stdout;
34+
const {stdout, stderr} = await exec(cmd);
35+
logs = stdout || new Error(stderr);
3436
}
3537

3638
await exec(`rm '/tmp/${outputFilename}'`);
3739
await cleanupTempFiles();
3840

39-
try {
40-
const logsString = logs.toString();
41-
42-
return getConvertedFilePath(logsString);
43-
} catch (error) {
44-
if (
45-
error instanceof Error &&
46-
error.message.includes(`Cannot read properties of null (reading '1')`)
47-
) {
48-
throw new Error(`Cannot generate PDF preview for .${outputFilename.split('.').pop()} file`, {
49-
cause: error,
50-
});
51-
}
52-
53-
throw error;
41+
if (logs instanceof Error) {
42+
throw new Error(`Cannot generate PDF preview for .${outputFilename.split('.').pop()} file`, {
43+
cause: logs,
44+
});
5445
}
46+
47+
return getConvertedFilePath(logs.toString());
5548
}

0 commit comments

Comments
 (0)