@@ -47,36 +47,40 @@ export class LocalFileExtractorExecutor extends AbstractBlockExecutor<
4747 } ) ;
4848 }
4949
50+ let rawData : Buffer | undefined = undefined ;
5051 try {
51- const rawData = await fs . readFile ( filePath ) ;
52-
53- // Infer FileName and FileExtension from filePath
54- const fileName = path . basename ( filePath ) ;
55- const extName = path . extname ( fileName ) ;
56- const fileExtension =
57- inferFileExtensionFromFileExtensionString ( extName ) ??
58- FileExtension . NONE ;
59-
60- // Infer Mimetype from FileExtension, if not inferrable, then default to application/octet-stream
61- const mimeType : MimeType | undefined =
62- inferMimeTypeFromFileExtensionString ( fileExtension ) ??
63- MimeType . APPLICATION_OCTET_STREAM ;
64-
65- // Create file and return file
66- const file = new BinaryFile (
67- fileName ,
68- fileExtension ,
69- mimeType ,
70- rawData . buffer as ArrayBuffer ,
71- ) ;
72-
73- context . logger . logDebug ( `Successfully extraced file ${ filePath } ` ) ;
74- return R . ok ( file ) ;
75- } catch ( error ) {
52+ rawData = await fs . readFile ( filePath ) ;
53+ } catch ( error : unknown ) {
54+ const message =
55+ error instanceof Error
56+ ? error . message
57+ : `Could not read file ${ filePath } ` ;
7658 return R . err ( {
77- message : `File ' ${ filePath } ' not found.` ,
59+ message : message ,
7860 diagnostic : { node : context . getCurrentNode ( ) , property : 'filePath' } ,
7961 } ) ;
8062 }
63+
64+ // Infer FileName and FileExtension from filePath
65+ const fileName = path . basename ( filePath ) ;
66+ const extName = path . extname ( fileName ) ;
67+ const fileExtension =
68+ inferFileExtensionFromFileExtensionString ( extName ) ?? FileExtension . NONE ;
69+
70+ // Infer Mimetype from FileExtension, if not inferrable, then default to application/octet-stream
71+ const mimeType : MimeType | undefined =
72+ inferMimeTypeFromFileExtensionString ( fileExtension ) ??
73+ MimeType . APPLICATION_OCTET_STREAM ;
74+
75+ // Create file and return file
76+ const file = new BinaryFile (
77+ fileName ,
78+ fileExtension ,
79+ mimeType ,
80+ rawData . buffer as ArrayBuffer ,
81+ ) ;
82+
83+ context . logger . logDebug ( `Successfully extraced file ${ filePath } ` ) ;
84+ return R . ok ( file ) ;
8185 }
8286}
0 commit comments