简体   繁体   中英

FlutterFire: Calling cloud function throws an internal error with no details - FirebaseFunctionsException [firebase_functions/17999]

I'm trying to call a very simple cloud function from my Flutter app following the FlutterFire docs , but I'm getting a pretty unreadable error. The error occurs whether I'm using the emulators, or attempting to call the function fully deployed with Firebase.

My cloud function code:

import * as functions from "firebase-functions";

export const ping = functions.https.onCall(() => ({ ping: "pong" }));

And my Flutter code in main.dart :

import 'package:cloud_functions/cloud_functions.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:my_app/firebase_options.dart';
import 'package:my_app/my_app.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); // Uses options configured by FlutterFire CLI

  // Does not work regardless of whether this line is commented out
  // FirebaseFunctions.instance.useFunctionsEmulator('localhost', 5001);

  HttpsCallable ping = FirebaseFunctions.instance.httpsCallable('ping');
  await ping(); // Exception thrown on this line

  runApp(const MyApp());
}

When running this code, I get a FirebaseFunctionsException ([firebase_functions/17999] An internal error has occurred, print and inspect the error details for more information. error: 异常详情

Even as I dive deeper into the call stack, I'm not able to get any helpful information. Setting a breakpoint in the call method of MethodChannelHttpsCallable shows me that the exception is thrown when calling the MethodChannelFirebaseFunctions.channel.invokeMethod method, but I can't see any immediately obvious reason why that would be failing.

I'm using other FlutterFire libraries in my app (specifically Auth and Firestore), with no problems at all, both with the emulator and the deployed Firebase project.

I found out how to solve this problem. In the Emulator UI, add a user in the Authentication tab and make your App login with him only once. Then you can logout and delete this user. After that my function stopped giving error 17999 and it worked normally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM