openfoodfacts / smooth-app

🤳🥫 The new Open Food Facts mobile application for Android and iOS, crafted with Flutter and Dart
https://world.openfoodfacts.org/open-food-facts-mobile-app?utm_source=off&utf_medium=web&utm_campaign=github-repo
Apache License 2.0
853 stars 282 forks source link

_CastError: Null check operator used on a null value #2255

Closed sentry-io[bot] closed 1 year ago

sentry-io[bot] commented 2 years ago

Sentry Issue: SMOOTHIE-WS

_CastError: Null check operator used on a null value
  File "history_page.dart", line 23, in _HistoryPageState.didChangeDependencies.<fn>
monsieurtanuki commented 2 years ago

From what I read in the code, line 23 is a refresh setState({}) method that calls Widget ProductListPage. And in ProductListPage we only force a value to be not null with product.barcode! (several times). Could there be a null barcode in history? Should we automatically get rid of those products? (I still haven't understood the use case behind null barcodes and even worse how we're supposed to deal with them).

monsieurtanuki commented 2 years ago

In order to get rid of this crash, we could simply dismiss products that have a null barcode in ProductListPage. Trying to understand how that happens, it would be nice to send some message back home, like "I know it's unexpected and I've just got rid of a barcode-less product": @g123k what tool do you suggest? sentry matomo fimber?

g123k commented 2 years ago

Just use the Logs class it will do all at the same time

monsieurtanuki commented 2 years ago

@g123k Thank you! Just thinking about it again, in your migration, did you download products?

g123k commented 2 years ago

Yes

monsieurtanuki commented 2 years ago

@g123k Would you point me to the piece of code where the download actually takes place? There are tons of "unexpected" errors in https://sentry.io/organizations/openfoodfacts/issues/3377849466/?project=5376745&referrer=weekly-email where products from a list are not in the product table.

Maybe it comes from your migration, maybe it comes from my hive-sqflite migration, maybe it's something else.

Anyway we should probably propose a database consistency check-up and repair button.

g123k commented 2 years ago

The only code was based on your import feature: https://github.com/openfoodfacts/smooth-app/blob/develop/packages/smooth_app/lib/helpers/data_importer/product_list_import_export.dart

M123-dev commented 2 years ago

Is fixed, likely because we now load the list of barcodes and not the list of products anymore

M123-dev commented 2 years ago

No it happend again

monsieurtanuki commented 2 years ago

Looks similar to https://github.com/flutter/flutter/issues/81684 My hunch: perhaps it's because we "open" the history page without showing it (as it's not the main tab).