Skip to content

Commit 1666668

Browse files
committedFeb 17, 2025
Refactor importActorProfile function to improve error handling and remove unused options
1 parent c2417d3 commit 1666668

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed
 

‎out/test-export-2024-01-01.tar

0 Bytes
Binary file not shown.

‎src/index.ts

+7-20
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export async function importActorProfile(
192192
onError?: (error: Error, context: { fileName?: string }) => void
193193
} = {}
194194
): Promise<Record<string, any>> {
195-
const { console = undefined, onError = undefined } = options
195+
const { console = undefined } = options
196196
const extract = tar.extract()
197197
const result: Record<string, any> = {}
198198

@@ -242,13 +242,8 @@ export async function importActorProfile(
242242
})
243243

244244
stream.on('error', (error: any) => {
245-
const errorMessage = `Stream error on file ${fileName}: ${error.message}`
246-
if (onError) {
247-
onError(new Error(errorMessage), { fileName })
248-
} else {
249-
reject(new Error(errorMessage))
250-
}
251-
next() // Continue even on stream error
245+
console?.error(`Stream error on file ${fileName}:`, error.message)
246+
next(error) // Continue even on stream error
252247
})
253248
})
254249

@@ -258,21 +253,13 @@ export async function importActorProfile(
258253
})
259254

260255
extract.on('error', (error) => {
261-
const errorMessage = `Error during tar extraction: ${error.message}`
262-
if (onError) {
263-
onError(new Error(errorMessage), {})
264-
} else {
265-
reject(new Error(errorMessage))
266-
}
256+
console?.error('Error during tar extraction:', error.message)
257+
reject(new Error('Failed to extract tar file.'))
267258
})
268259

269260
tarStream.on('error', (error) => {
270-
const errorMessage = `Error in tar stream: ${error.message}`
271-
if (onError) {
272-
onError(new Error(errorMessage), {})
273-
} else {
274-
reject(new Error(errorMessage))
275-
}
261+
console?.error('Error in tar stream:', error.message)
262+
reject(new Error('Failed to process tar stream.'))
276263
})
277264

278265
tarStream.pipe(extract)

0 commit comments

Comments
 (0)
Please sign in to comment.