Skip to content

Commit fe940b3

Browse files
committed
[BLD-395] Dashboard: Show error UI when parsing CSV fails (#8223)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR improves error handling in the `useCsvUpload` hook by adding a `try-catch` block around the CSV parsing logic. It ensures that if an error occurs during parsing or if the parsed data lacks an address, the component sets an error state and logs the error. ### Detailed summary - Introduced a `try-catch` block around the CSV parsing logic. - Added error handling to set `noCsv` to `true` if the parsed data's first entry does not have an `address`. - Ensured that any errors during parsing are logged to the console. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Prevents crashes during CSV uploads by handling parse errors gracefully. * Ensures invalid or malformed CSV files are detected and flagged without updating data. * Maintains existing behavior for valid files, only updating data when required fields are present. * Improves reliability of the upload flow with clearer invalid-file handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 080d7f2 commit fe940b3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

apps/dashboard/src/@/hooks/useCsvUpload.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,17 @@ export function useCsvUpload<
119119
}
120120
Papa.parse(csv, {
121121
complete: (results) => {
122-
const data = props.csvParser(results.data as T[]);
123-
if (!data[0]?.address) {
122+
try {
123+
const data = props.csvParser(results.data as T[]);
124+
if (!data[0]?.address) {
125+
setNoCsv(true);
126+
return;
127+
}
128+
setRawData(data);
129+
} catch (error) {
130+
console.error(error);
124131
setNoCsv(true);
125-
return;
126132
}
127-
setRawData(data);
128133
},
129134
header: true,
130135
});

0 commit comments

Comments
 (0)