grpc-dart icon indicating copy to clipboard operation
grpc-dart copied to clipboard

GrpcError details list is empty on client side

Open balesz opened this issue 4 years ago • 2 comments

I throw a GrpcError.failedPrecondition error on server side with a GeneratedMessage typed object in the details list. On the client side I get the GrpcError with the proper status code and error message, but the details list is empty.

Proto

syntax = "proto3";
package test;

service Test {
  rpc Test(Empty) returns (Empty);
}

message Empty {
}

message Detail {
  int32 code = 1;
}

Test

import 'package:flutter_test/flutter_test.dart';
import 'package:grpc/grpc.dart';

import 'test.pbgrpc.dart';

void main() {
  test('test', () async {
    await Server([TestService()]).serve(address: "localhost", port: 8080);
    final opts = ChannelOptions(credentials: ChannelCredentials.insecure());
    final channel = ClientChannel('localhost', port: 8080, options: opts);
    try {
      await TestClient(channel).test(Empty());
    } on GrpcError catch (error) {
      expect(error, isA<GrpcError>());
      expect(error.message, equals('ERROR'));
      expect(error.details, isNotEmpty);
    }
  });
}

class TestService extends TestServiceBase {
  @override
  Future<Empty> test(ServiceCall call, Empty request) {
    throw GrpcError.failedPrecondition("ERROR", [Detail(code: 444)]);
  }
}

balesz avatar Jul 26 '21 22:07 balesz

PR from @acoutts (https://github.com/grpc/grpc-dart/pull/349) added deserialization of error details for client size, but nobody contributed serialization of error details for server side so far.

PRs are welcome.

mraleph avatar Aug 09 '21 10:08 mraleph

Was there any progress on this item?

wolframm avatar Feb 21 '23 09:02 wolframm