File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 1
1
import childProcess from 'child_process' ;
2
2
import util from 'util' ;
3
+ import path from 'node:path' ;
3
4
import { cleanupTempFiles } from './cleanup' ;
4
5
import { getConvertedFilePath } from './logs' ;
5
6
@@ -25,16 +26,27 @@ export async function convertTo(filename: string, format: string): Promise<strin
25
26
const cmd = `cd /tmp && ${ LO_BINARY_PATH } ${ argumentsString } --convert-to ${ format } --outdir /tmp '/tmp/${ outputFilename } '` ;
26
27
27
28
let logs ;
29
+ let err ;
28
30
29
31
// due to an unknown issue, we need to run command twice
30
32
try {
31
- logs = ( await exec ( cmd ) ) . stdout ;
33
+ const { stdout, stderr} = await exec ( cmd ) ;
34
+ logs = stdout ;
35
+ err = stderr ;
32
36
} catch ( e ) {
33
- logs = ( await exec ( cmd ) ) . stdout ;
37
+ const { stdout, stderr} = await exec ( cmd ) ;
38
+ logs = stdout ;
39
+ err = stderr ;
40
+ } finally {
41
+ await exec ( `rm '/tmp/${ outputFilename } '` ) ;
42
+ await cleanupTempFiles ( ) ;
34
43
}
35
44
36
- await exec ( `rm '/tmp/${ outputFilename } '` ) ;
37
- await cleanupTempFiles ( ) ;
45
+ if ( err ) {
46
+ throw new Error ( `Cannot generate PDF preview for .${ path . extname ( outputFilename ) } file` , {
47
+ cause : logs ,
48
+ } ) ;
49
+ }
38
50
39
51
return getConvertedFilePath ( logs . toString ( ) ) ;
40
52
}
You can’t perform that action at this time.
0 commit comments