Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e5bb242

Browse files
committedFeb 17, 2025·
Refactor importActorProfile function to streamline error handling and remove redundant console logs
1 parent 739f3ff commit e5bb242

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed
 

‎src/index.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,7 @@ export async function importActorProfile(
192192
console?: Pick<Console, 'log' | 'warn' | 'error'>
193193
onError?: (error: Error, context: { fileName?: string }) => void
194194
} = {}
195-
tarStream: Readable,
196-
options: {
197-
console?: Pick<Console, 'log' | 'warn' | 'error'>
198-
onError?: (error: Error, context: { fileName?: string }) => void
199-
} = {}
200195
): Promise<Record<string, any>> {
201-
const { console = undefined } = options
202196
const { console = undefined } = options
203197
const extract = tar.extract()
204198
const result: Record<string, any> = {}
@@ -230,22 +224,15 @@ export async function importActorProfile(
230224
if (fileName.endsWith('.json')) {
231225
result[fileName] = JSON.parse(content)
232226
console?.log('Parsed JSON file successfully:', fileName)
233-
console?.log('Parsed JSON file successfully:', fileName)
234227
} else if (fileName.endsWith('.yaml') || fileName.endsWith('.yml')) {
235228
result[fileName] = YAML.parse(content)
236229
} else if (fileName.endsWith('.csv')) {
237230
result[fileName] = content
238231
} else {
239232
console?.warn(`Unsupported file type: ${fileName}, skipping...`)
240-
console?.warn(`Unsupported file type: ${fileName}, skipping...`)
241233
}
242234
} catch (error: any) {
243-
const errorMessage = `Error processing file ${fileName}: ${error.message}`
244-
if (onError) {
245-
onError(new Error(errorMessage), { fileName })
246-
} else {
247-
reject(new Error(errorMessage))
248-
}
235+
next(error)
249236
} finally {
250237
next() // Always continue
251238
}
@@ -260,19 +247,16 @@ export async function importActorProfile(
260247
})
261248

262249
extract.on('finish', () => {
263-
console?.log('All files processed successfully.')
264250
console?.log('All files processed successfully.')
265251
resolve(result)
266252
})
267253

268254
extract.on('error', (error) => {
269-
console?.error('Error during tar extraction:', error.message)
270255
console?.error('Error during tar extraction:', error.message)
271256
reject(new Error('Failed to extract tar file.'))
272257
})
273258

274259
tarStream.on('error', (error) => {
275-
console?.error('Error in tar stream:', error.message)
276260
console?.error('Error in tar stream:', error.message)
277261
reject(new Error('Failed to process tar stream.'))
278262
})

0 commit comments

Comments
 (0)
Please sign in to comment.