From 9fa715f7ccb205f4b2324a8a25eef50eaf383c89 Mon Sep 17 00:00:00 2001 From: nucoinha <159596264+nucoinha@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:10:20 -0300 Subject: [PATCH] Allow user to handle errors The code doesn't reject the promise when a error occurs so makes it impossible for the user to catch the problem. I'm not sure if this patch will work but this is an issue anyway. --- src/danfojs-base/io/browser/io.csv.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/danfojs-base/io/browser/io.csv.ts b/src/danfojs-base/io/browser/io.csv.ts index daac8ba9..936c77bc 100644 --- a/src/danfojs-base/io/browser/io.csv.ts +++ b/src/danfojs-base/io/browser/io.csv.ts @@ -48,12 +48,13 @@ import Papa from 'papaparse' const $readCSV = async (file: any, options?: CsvInputOptionsBrowser): Promise => { const frameConfig = options?.frameConfig || {} - return new Promise(resolve => { + return new Promise((resolve, reject) => { Papa.parse(file, { header: true, dynamicTyping: true, skipEmptyLines: 'greedy', ...options, + error: (error, file) => reject(error,file), download: true, complete: results => { const df = new DataFrame(results.data, frameConfig); @@ -81,7 +82,7 @@ const $readCSV = async (file: any, options?: CsvInputOptionsBrowser): Promise void, options: CsvInputOptionsBrowser,): Promise => { const frameConfig = options?.frameConfig || {} - return new Promise(resolve => { + return new Promise((resolve, reject) => { let count = 0 Papa.parse(file, { ...options, @@ -92,7 +93,8 @@ const $streamCSV = async (file: string, callback: (df: DataFrame) => void, optio const df = new DataFrame([results.data], { ...frameConfig, index: [count++] }); callback(df); }, - complete: () => resolve(null) + complete: () => resolve(null), + error: (error, file) => reject(error,file) }); }); };