jackedelic / cloud-function-crud-example

This is a code base for tutorial on how to integrate google cloud function (and Firestore) into Flutter project using CRUD.
https://medium.com/@jackwong_60367/cloud-function-flutter-128b8c3695b4
6 stars 2 forks source link

Unhandled Exception: PlatformException(functionsError, Cloud function failed with exception., {code: INTERNAL, details: null, message: INTERNAL}) #1

Open ebot64 opened 4 years ago

ebot64 commented 4 years ago

First of all, thank you for this cloud function CRUD example. The CloudFunctions.instance.call has changed so I changed your implementation of the following code

CloudFunctions.instance.call(
    functionName: "addUser",
    parameters: {
      "name": _nameTextController.text,
      "email": _emailTextController.text
  });

to this

final HttpsCallable callable = CloudFunctions.instance
    .getHttpsCallable(functionName: "addUser");
await callable
    .call({
      "name": _nameTextController.text,
      "email": _emailTextController.text
    })
    .then((value) => print(value.data))
    .catchError((onError) => print(onError.toString()))
    .whenComplete(() => print('finally complete'));

With this, the new user is added to firestore as expected, but I am having this Platform exception. What can be the cause?

E/flutter (14362): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(functionsError, Cloud function failed with exception., {code: INTERNAL, details: null, message: INTERNAL})
E/flutter (14362): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:572:7)
E/flutter (14362): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:161:18)
E/flutter (14362): <asynchronous suspension>
E/flutter (14362): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:334:12)
E/flutter (14362): #3      MethodChannelCloudFunctions.callCloudFunction (package:cloud_functions_platform_interface/src/method_channel_cloud_functions.dart:43:15)
E/flutter (14362): #4      HttpsCallable.call (package:cloud_functions/src/https_callable.dart:33:12)
E/flutter (14362): #5      _MyHomePageState._showAddUserDialogBox.<anonymous closure>.<anonymous closure> (package:cloudfunctionsample/main.dart:156:36)
E/flutter (14362): #6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
E/flutter (14362): #7      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38)
E/flutter (14362): #8      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
E/flutter (14362): #9      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
E/flutter (14362): #10     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
E/flutter (14362): #11     BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:219:7)
E/flutter (14362): #12     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:477:9)
E/flutter (14362): #13     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:78:12)
E/flutter (14362): #14     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:124:9)
E/flutter (14362): #15     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (14362): #16     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:122:18)
E/flutter (14362): #17     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:108:7)
E/flutter (14362): #18     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:220:19)
E/flutter (14362): #19     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
E/flutter (14362): #20     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
E/flutter (14362): #21     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
E/flutter (14362): #22     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
E/flutter (14362): #23     _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (14362): #24     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (14362): #25     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (14362): #26     _invoke1 (dart:ui/hooks.dart:281:10)
E/flutter (14362): #27     _dispatchPointerDataPacket (dart:ui/hooks.dart:190:5)
E/flutter (14362): 
jackedelic commented 4 years ago

Thanks for pointing out the implementation change🙂. Instead of chaining with then() and catchError(), could you try try ... catch ?

jackedelic commented 4 years ago

Referencing an example from cloud_functions package :

try {
  final HttpsCallableResult result = await callable.call(
    <String, dynamic>{
      'message': 'hello world!',
      'count': _responseCount,
     },
    );
    print(result.data);
   });
  } on CloudFunctionsException catch (e) {
    print('caught firebase functions exception');
    print(e.code);
    print(e.message);
    print(e.details);
  } catch (e) {
    print('caught generic exception');
    print(e);
}