PlatformException(函数错误,云函数失败,Firebase云函数出现异常

PlatformException(函数错误,云函数失败,Firebase云函数出现异常,firebase,flutter,dart,google-cloud-functions,Firebase,Flutter,Dart,Google Cloud Functions,当数据为空时会出现此错误。但我会处理此错误。为什么引发异常?如何处理null PlatformException(函数错误,云函数失败 异常.,{代码:未找到,详细信息:null,消息:驱动程序不可用 空}) 颤振代码 Future<UserCollection> findDrivers(LatLng latLng) async { final HttpsCallable callable = CloudFunctions.instance .getHttpsCall

当数据为空时会出现此错误。但我会处理此错误。为什么引发异常?如何处理null

PlatformException(函数错误,云函数失败 异常.,{代码:未找到,详细信息:null,消息:驱动程序不可用 空})

颤振代码

Future<UserCollection> findDrivers(LatLng latLng) async {
  final HttpsCallable callable = CloudFunctions.instance
      .getHttpsCallable(functionName: 'findDrivers')
        ..timeout = const Duration(seconds: 30);

  try {
    final HttpsCallableResult result = await callable.call(
      <String, dynamic>{'lat': latLng.latitude, 'lng': latLng.longitude},
    );

    if(result.data['users'] != null){
      UserCollection userCollection = UserCollection.fromMap(result.data);
      return userCollection;
    }else{
      print('called: return null');//never called
      return null;
    }
  } on CloudFunctionsException catch (e) {
    print('caught firebase functions exception');
    print(e.code);
    print(e.message);
    print(e.details);
    return null;
  }

  catch (e) {
    print('caught generic exception');//firing here
    print(e);
    return null;
  }
}
export const getLocationsByType = async function () {
  const db = admin.firestore();

  const query = await db.collection("users")
    .get();


  if (query.empty){
    return null;
  }
  else {
    const trips: Array<any> = [];
     query.docs.forEach((doc) => {
      trips.push(doc.data())
    })
    return trips;
  }

}

对于云函数来说,这看起来不像是完整的代码。请编辑问题以显示所涉及的所有内容,尤其是函数定义。@DougStevenson I editedIt仍然不完整。您在哪里使用onCall定义了函数?您的函数抛出“未找到”在多个地方出现错误。我们无法知道是哪一个导致了您在客户机中看到的错误。@BloodLoss您找到答案了吗?我面临着同样的问题
exports.findDrivers = functions.https.onCall(async (data: any, context: any) => {

    if (data.lat !== undefined && data.lng !== undefined && data.type !== undefined) {

       const users = await getLocationsByType();
      if (users) {
        if (users.length !== 0) {
            return {
                users: users
            };
        }
        else
            throw new functions.https.HttpsError('not-found', 'Not Found Drivers');//this throw return

    } else {
        throw new functions.https.HttpsError('not-found', 'Drivers are null');
    }

    }
});