Skip to content

fix: handle empty CSV data and empty collection on startup#1677

Open
nazifsco wants to merge 1 commit into
foss42:mainfrom
nazifsco:fix/csv-previewer-and-collection-empty-crash
Open

fix: handle empty CSV data and empty collection on startup#1677
nazifsco wants to merge 1 commit into
foss42:mainfrom
nazifsco:fix/csv-previewer-and-collection-empty-crash

Conversation

@nazifsco

Copy link
Copy Markdown

Fixes two RangeError crashes:

Fix 1 -- CsvPreviewer crashes on empty CSV response (closes #1647)

lib/widgets/previewer_csv.dart accessed csvData[0] without checking if the list was empty. Any API response returning empty or malformed CSV would crash the app.

// before
final List<List<dynamic>> csvData = csv.decode(body);
return SingleChildScrollView(...) // crashes if csvData is empty

// after
final List<List<dynamic>> csvData = csv.decode(body);
if (csvData.isEmpty) return errorWidget;
return SingleChildScrollView(...)

Fix 2 -- CollectionStateNotifier crashes on empty collection (closes #1640)

lib/providers/collection_providers.dart accessed requestSequenceProvider[0] unconditionally. On first launch or after clearing all requests, this crashed with RangeError: Index out of range.

// before
ref.read(selectedIdStateProvider.notifier).state = ref.read(
  requestSequenceProvider,
)[0];

// after
final ids = ref.read(requestSequenceProvider);
ref.read(selectedIdStateProvider.notifier).state =
    ids.isNotEmpty ? ids[0] : null;

- CsvPreviewer: return errorWidget when csvData is empty instead of
  crashing with RangeError on csvData[0] (fixes foss42#1647)
- CollectionStateNotifier: guard requestSequenceProvider access so
  selectedId is null when collection is empty instead of crashing
  on first launch or after clearing all requests (fixes foss42#1640)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CsvPreviewer crashes with RangeError when CSV data is empty [Bug] CollectionStateNotifier crashes with RangeError when collection is empty

1 participant