mawaqit / android-tv-app

Prayer times App for Android TV
https://mawaqit.net
Other
40 stars 17 forks source link

ArgumentError: Invalid argument (onError): Error handler must accept one Object or one Object and a StackTrace a... #949

Closed sentry-io[bot] closed 10 months ago

sentry-io[bot] commented 11 months ago

Sentry Issue: ANDROIDTV-3Q

ArgumentError: Invalid argument (onError): Error handler must accept one Object or one Object and a StackTrace as arguments, and return a value of the returned future's type: Closure: () => Null
  File "weather_mixin.dart", line 20, in WeatherMixin.loadWeather
  File "mosque_manager.dart", line 163, in MosqueManager.fetchMosque
  File "mosque_manager.dart", line 93, in MosqueManager.loadFromLocale
  File "mosque_manager.dart", line 58, in MosqueManager.init
  File "SplashScreen.dart", line 76, in _SplashScreen._initSettings
...
(7 additional frame(s) were not displayed)
ghassenbenzahra123 commented 11 months ago

The issue has been successfully addressed by the pull request #935. In order to further validate and ensure the effectiveness of the fix, I've created the unit test below:

// Import necessary packages for testing
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:mawaqit/src/helpers/Api.dart';

// Define necessary classes for testing
class Weather {}

class Mosque {
  final String uuid;

  Mosque({required this.uuid});
}

class WeatherService {
  Weather? weather;

  late StreamSubscription<void> _weatherSubscription =
      Stream.empty().listen((_) {});

  late Future<dynamic> Function(String) _getWeather;

  WeatherService({Future<Weather> Function(String)? getWeather})
      : _getWeather = getWeather ?? Api.getWeather;

  void loadWeather(Mosque mosque) {
    if (mosque.uuid != null) {
      _weatherSubscription.cancel().catchError((e) {});
    }
  }
}

void main() {
  group('Weather functionality tests', () {
    late WeatherService weatherService;

    setUp(() {
      weatherService = WeatherService();
    });

    // Test case: Verify that 'loadWeather' cancels subscription and sets weather to null when an exception occurs
    test('loadWeather cancels subscription', () async {
      weatherService._getWeather =
          (String uuid) => throw Exception('Test exception');

      weatherService.loadWeather(Mosque(uuid: 'test_uuid'));

      expect(weatherService.weather, isNull);
    });
  });

Test Results

📷 Before the fix :

📷 After the fix :

ibrahim-zehhaf-mawaqit commented 10 months ago

@ghassenbenzahra123 which PR is linked to this issue ? can you link it please