mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-03 03:24:08 +00:00
explicityly print the internal error from DispatchError
This commit is contained in:
parent
18d13a3cb2
commit
4c93b04f3d
@ -43,12 +43,12 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {
|
|||||||
|
|
||||||
SignInState stateFromCode(UserError error) {
|
SignInState stateFromCode(UserError error) {
|
||||||
switch (error.code) {
|
switch (error.code) {
|
||||||
case UserErrCode.EmailFormatInvalid:
|
case ErrorCode.EmailFormatInvalid:
|
||||||
return state.copyWith(
|
return state.copyWith(
|
||||||
isSubmitting: false,
|
isSubmitting: false,
|
||||||
emailError: some(error.msg),
|
emailError: some(error.msg),
|
||||||
passwordError: none());
|
passwordError: none());
|
||||||
case UserErrCode.PasswordFormatInvalid:
|
case ErrorCode.PasswordFormatInvalid:
|
||||||
return state.copyWith(
|
return state.copyWith(
|
||||||
isSubmitting: false,
|
isSubmitting: false,
|
||||||
passwordError: some(error.msg),
|
passwordError: some(error.msg),
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import 'package:flowy_infra/time/duration.dart';
|
|||||||
import 'package:flowy_infra_ui/widget/route/animation.dart';
|
import 'package:flowy_infra_ui/widget/route/animation.dart';
|
||||||
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart';
|
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart' as workspace;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ class WelcomeRoute implements IWelcomeRoute {
|
|||||||
(workspace) =>
|
(workspace) =>
|
||||||
_pushToScreen(context, HomeScreen(repo.user, workspace.id)),
|
_pushToScreen(context, HomeScreen(repo.user, workspace.id)),
|
||||||
(error) async {
|
(error) async {
|
||||||
assert(error.code == WsErrCode.CurrentWorkspaceNotFound);
|
assert(error.code == workspace.ErrorCode.CurrentWorkspaceNotFound);
|
||||||
final screen = WorkspaceSelectScreen(repo: repo);
|
final screen = WorkspaceSelectScreen(repo: repo);
|
||||||
final workspaceId = await Navigator.of(context).push(
|
final workspaceId = await Navigator.of(context).push(
|
||||||
PageRoutes.fade(
|
PageRoutes.fade(
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import 'package:flowy_sdk/protobuf/flowy-workspace/workspace_create.pb.dart';
|
|||||||
export 'package:flowy_sdk/protobuf/flowy-workspace/workspace_create.pb.dart';
|
export 'package:flowy_sdk/protobuf/flowy-workspace/workspace_create.pb.dart';
|
||||||
export 'package:flowy_sdk/protobuf/flowy-user/errors.pb.dart';
|
export 'package:flowy_sdk/protobuf/flowy-user/errors.pb.dart';
|
||||||
export 'package:flowy_sdk/protobuf/flowy-user/user_detail.pb.dart';
|
export 'package:flowy_sdk/protobuf/flowy-user/user_detail.pb.dart';
|
||||||
export 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
|
||||||
|
|
||||||
typedef UserCreateWorkspaceCallback = void Function(
|
typedef UserCreateWorkspaceCallback = void Function(
|
||||||
Either<List<Workspace>, WorkspaceError> workspacesOrFailed);
|
Either<List<Workspace>, WorkspaceError> workspacesOrFailed);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart';
|
import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart';
|
||||||
import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart';
|
import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart' as workspace;
|
||||||
import 'package:app_flowy/workspace/domain/i_app.dart';
|
import 'package:app_flowy/workspace/domain/i_app.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
||||||
export 'package:app_flowy/workspace/domain/i_app.dart';
|
export 'package:app_flowy/workspace/domain/i_app.dart';
|
||||||
@ -13,12 +13,12 @@ class IAppImpl extends IApp {
|
|||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Either<List<View>, WorkspaceError>> getViews() {
|
Future<Either<List<View>, workspace.WorkspaceError>> getViews() {
|
||||||
return repo.getViews();
|
return repo.getViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Either<View, WorkspaceError>> createView(
|
Future<Either<View, workspace.WorkspaceError>> createView(
|
||||||
{required String name, String? desc, required ViewType viewType}) {
|
{required String name, String? desc, required ViewType viewType}) {
|
||||||
return repo.createView(name, desc ?? "", viewType).then((result) {
|
return repo.createView(name, desc ?? "", viewType).then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
@ -28,14 +28,15 @@ class IAppImpl extends IApp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<View, WorkspaceError>> _createDoc(View view) async {
|
Future<Either<View, workspace.WorkspaceError>> _createDoc(View view) async {
|
||||||
switch (view.viewType) {
|
switch (view.viewType) {
|
||||||
case ViewType.Doc:
|
case ViewType.Doc:
|
||||||
final docRepo = DocRepository(docId: view.id);
|
final docRepo = DocRepository(docId: view.id);
|
||||||
final result = await docRepo.createDoc(
|
final result = await docRepo.createDoc(
|
||||||
name: view.name, desc: "", text: "[{\"insert\":\"\\n\"}]");
|
name: view.name, desc: "", text: "[{\"insert\":\"\\n\"}]");
|
||||||
return result.fold((l) => left(view), (r) {
|
return result.fold((l) => left(view), (r) {
|
||||||
return right(WorkspaceError(code: WsErrCode.Unknown, msg: r.msg));
|
return right(workspace.WorkspaceError(
|
||||||
|
code: workspace.ErrorCode.Unknown, msg: r.msg));
|
||||||
});
|
});
|
||||||
default:
|
default:
|
||||||
return left(view);
|
return left(view);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:app_flowy/workspace/domain/i_user.dart';
|
import 'package:app_flowy/workspace/domain/i_user.dart';
|
||||||
import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
|
import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
||||||
export 'package:app_flowy/workspace/domain/i_user.dart';
|
export 'package:app_flowy/workspace/domain/i_user.dart';
|
||||||
export 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
|
export 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import 'package:flowy_sdk/protobuf/flowy-document/protobuf.dart';
|
|||||||
// ignore: unused_import
|
// ignore: unused_import
|
||||||
import 'package:flowy_sdk/protobuf/flowy-infra/protobuf.dart';
|
import 'package:flowy_sdk/protobuf/flowy-infra/protobuf.dart';
|
||||||
import 'package:protobuf/protobuf.dart';
|
import 'package:protobuf/protobuf.dart';
|
||||||
// import 'dart:convert' show utf8;
|
import 'dart:convert' show utf8;
|
||||||
import 'error.dart';
|
import 'error.dart';
|
||||||
|
|
||||||
part 'code_gen.dart';
|
part 'code_gen.dart';
|
||||||
@ -51,12 +51,18 @@ Future<Either<Uint8List, Uint8List>> _extractPayload(
|
|||||||
return responseFuture.then((result) {
|
return responseFuture.then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
(response) {
|
(response) {
|
||||||
if (response.code == FFIStatusCode.Ok) {
|
switch (response.code) {
|
||||||
return left(Uint8List.fromList(response.payload));
|
case FFIStatusCode.Ok:
|
||||||
} else {
|
return left(Uint8List.fromList(response.payload));
|
||||||
// final error = utf8.decode(response.payload);
|
case FFIStatusCode.Err:
|
||||||
// Log.error("Dispatch error: $error");
|
return right(Uint8List.fromList(response.payload));
|
||||||
return right(Uint8List.fromList(response.payload));
|
case FFIStatusCode.Internal:
|
||||||
|
final error = utf8.decode(response.payload);
|
||||||
|
Log.error("Dispatch internal error: $error");
|
||||||
|
return right(emptyBytes());
|
||||||
|
default:
|
||||||
|
Log.error("Impossible to here");
|
||||||
|
return right(emptyBytes());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(error) {
|
(error) {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ export 'ffi_response.pbenum.dart';
|
|||||||
class FFIResponse extends $pb.GeneratedMessage {
|
class FFIResponse extends $pb.GeneratedMessage {
|
||||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'FFIResponse', createEmptyInstance: create)
|
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'FFIResponse', createEmptyInstance: create)
|
||||||
..a<$core.List<$core.int>>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'payload', $pb.PbFieldType.OY)
|
..a<$core.List<$core.int>>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'payload', $pb.PbFieldType.OY)
|
||||||
..e<FFIStatusCode>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: FFIStatusCode.Unknown, valueOf: FFIStatusCode.valueOf, enumValues: FFIStatusCode.values)
|
..e<FFIStatusCode>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: FFIStatusCode.Ok, valueOf: FFIStatusCode.valueOf, enumValues: FFIStatusCode.values)
|
||||||
..hasRequiredFields = false
|
..hasRequiredFields = false
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@ -10,14 +10,14 @@ import 'dart:core' as $core;
|
|||||||
import 'package:protobuf/protobuf.dart' as $pb;
|
import 'package:protobuf/protobuf.dart' as $pb;
|
||||||
|
|
||||||
class FFIStatusCode extends $pb.ProtobufEnum {
|
class FFIStatusCode extends $pb.ProtobufEnum {
|
||||||
static const FFIStatusCode Unknown = FFIStatusCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown');
|
static const FFIStatusCode Ok = FFIStatusCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Ok');
|
||||||
static const FFIStatusCode Ok = FFIStatusCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Ok');
|
static const FFIStatusCode Err = FFIStatusCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Err');
|
||||||
static const FFIStatusCode Err = FFIStatusCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Err');
|
static const FFIStatusCode Internal = FFIStatusCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Internal');
|
||||||
|
|
||||||
static const $core.List<FFIStatusCode> values = <FFIStatusCode> [
|
static const $core.List<FFIStatusCode> values = <FFIStatusCode> [
|
||||||
Unknown,
|
|
||||||
Ok,
|
Ok,
|
||||||
Err,
|
Err,
|
||||||
|
Internal,
|
||||||
];
|
];
|
||||||
|
|
||||||
static final $core.Map<$core.int, FFIStatusCode> _byValue = $pb.ProtobufEnum.initByValue(values);
|
static final $core.Map<$core.int, FFIStatusCode> _byValue = $pb.ProtobufEnum.initByValue(values);
|
||||||
|
|||||||
@ -12,14 +12,14 @@ import 'dart:typed_data' as $typed_data;
|
|||||||
const FFIStatusCode$json = const {
|
const FFIStatusCode$json = const {
|
||||||
'1': 'FFIStatusCode',
|
'1': 'FFIStatusCode',
|
||||||
'2': const [
|
'2': const [
|
||||||
const {'1': 'Unknown', '2': 0},
|
const {'1': 'Ok', '2': 0},
|
||||||
const {'1': 'Ok', '2': 1},
|
const {'1': 'Err', '2': 1},
|
||||||
const {'1': 'Err', '2': 2},
|
const {'1': 'Internal', '2': 2},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Descriptor for `FFIStatusCode`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
/// Descriptor for `FFIStatusCode`. Decode as a `google.protobuf.EnumDescriptorProto`.
|
||||||
final $typed_data.Uint8List fFIStatusCodeDescriptor = $convert.base64Decode('Cg1GRklTdGF0dXNDb2RlEgsKB1Vua25vd24QABIGCgJPaxABEgcKA0VychAC');
|
final $typed_data.Uint8List fFIStatusCodeDescriptor = $convert.base64Decode('Cg1GRklTdGF0dXNDb2RlEgYKAk9rEAASBwoDRXJyEAESDAoISW50ZXJuYWwQAg==');
|
||||||
@$core.Deprecated('Use fFIResponseDescriptor instead')
|
@$core.Deprecated('Use fFIResponseDescriptor instead')
|
||||||
const FFIResponse$json = const {
|
const FFIResponse$json = const {
|
||||||
'1': 'FFIResponse',
|
'1': 'FFIResponse',
|
||||||
|
|||||||
@ -3,13 +3,13 @@ use flowy_dispatch::prelude::{EventResponse, Payload, StatusCode};
|
|||||||
|
|
||||||
#[derive(ProtoBuf_Enum, Clone, Copy)]
|
#[derive(ProtoBuf_Enum, Clone, Copy)]
|
||||||
pub enum FFIStatusCode {
|
pub enum FFIStatusCode {
|
||||||
Unknown = 0,
|
Ok = 0,
|
||||||
Ok = 1,
|
Err = 1,
|
||||||
Err = 2,
|
Internal = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::default::Default for FFIStatusCode {
|
impl std::default::Default for FFIStatusCode {
|
||||||
fn default() -> FFIStatusCode { FFIStatusCode::Unknown }
|
fn default() -> FFIStatusCode { FFIStatusCode::Ok }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ProtoBuf, Default)]
|
#[derive(ProtoBuf, Default)]
|
||||||
@ -31,6 +31,7 @@ impl std::convert::From<EventResponse> for FFIResponse {
|
|||||||
let code = match resp.status_code {
|
let code = match resp.status_code {
|
||||||
StatusCode::Ok => FFIStatusCode::Ok,
|
StatusCode::Ok => FFIStatusCode::Ok,
|
||||||
StatusCode::Err => FFIStatusCode::Err,
|
StatusCode::Err => FFIStatusCode::Err,
|
||||||
|
StatusCode::Internal => FFIStatusCode::Internal,
|
||||||
};
|
};
|
||||||
|
|
||||||
// let msg = match resp.error {
|
// let msg = match resp.error {
|
||||||
|
|||||||
@ -77,7 +77,7 @@ impl FFIResponse {
|
|||||||
self.code
|
self.code
|
||||||
}
|
}
|
||||||
pub fn clear_code(&mut self) {
|
pub fn clear_code(&mut self) {
|
||||||
self.code = FFIStatusCode::Unknown;
|
self.code = FFIStatusCode::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Param is passed by value, moved
|
// Param is passed by value, moved
|
||||||
@ -116,7 +116,7 @@ impl ::protobuf::Message for FFIResponse {
|
|||||||
if !self.payload.is_empty() {
|
if !self.payload.is_empty() {
|
||||||
my_size += ::protobuf::rt::bytes_size(1, &self.payload);
|
my_size += ::protobuf::rt::bytes_size(1, &self.payload);
|
||||||
}
|
}
|
||||||
if self.code != FFIStatusCode::Unknown {
|
if self.code != FFIStatusCode::Ok {
|
||||||
my_size += ::protobuf::rt::enum_size(2, self.code);
|
my_size += ::protobuf::rt::enum_size(2, self.code);
|
||||||
}
|
}
|
||||||
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
|
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
|
||||||
@ -128,7 +128,7 @@ impl ::protobuf::Message for FFIResponse {
|
|||||||
if !self.payload.is_empty() {
|
if !self.payload.is_empty() {
|
||||||
os.write_bytes(1, &self.payload)?;
|
os.write_bytes(1, &self.payload)?;
|
||||||
}
|
}
|
||||||
if self.code != FFIStatusCode::Unknown {
|
if self.code != FFIStatusCode::Ok {
|
||||||
os.write_enum(2, ::protobuf::ProtobufEnum::value(&self.code))?;
|
os.write_enum(2, ::protobuf::ProtobufEnum::value(&self.code))?;
|
||||||
}
|
}
|
||||||
os.write_unknown_fields(self.get_unknown_fields())?;
|
os.write_unknown_fields(self.get_unknown_fields())?;
|
||||||
@ -196,7 +196,7 @@ impl ::protobuf::Message for FFIResponse {
|
|||||||
impl ::protobuf::Clear for FFIResponse {
|
impl ::protobuf::Clear for FFIResponse {
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
self.payload.clear();
|
self.payload.clear();
|
||||||
self.code = FFIStatusCode::Unknown;
|
self.code = FFIStatusCode::Ok;
|
||||||
self.unknown_fields.clear();
|
self.unknown_fields.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,9 +215,9 @@ impl ::protobuf::reflect::ProtobufValue for FFIResponse {
|
|||||||
|
|
||||||
#[derive(Clone,PartialEq,Eq,Debug,Hash)]
|
#[derive(Clone,PartialEq,Eq,Debug,Hash)]
|
||||||
pub enum FFIStatusCode {
|
pub enum FFIStatusCode {
|
||||||
Unknown = 0,
|
Ok = 0,
|
||||||
Ok = 1,
|
Err = 1,
|
||||||
Err = 2,
|
Internal = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::protobuf::ProtobufEnum for FFIStatusCode {
|
impl ::protobuf::ProtobufEnum for FFIStatusCode {
|
||||||
@ -227,18 +227,18 @@ impl ::protobuf::ProtobufEnum for FFIStatusCode {
|
|||||||
|
|
||||||
fn from_i32(value: i32) -> ::std::option::Option<FFIStatusCode> {
|
fn from_i32(value: i32) -> ::std::option::Option<FFIStatusCode> {
|
||||||
match value {
|
match value {
|
||||||
0 => ::std::option::Option::Some(FFIStatusCode::Unknown),
|
0 => ::std::option::Option::Some(FFIStatusCode::Ok),
|
||||||
1 => ::std::option::Option::Some(FFIStatusCode::Ok),
|
1 => ::std::option::Option::Some(FFIStatusCode::Err),
|
||||||
2 => ::std::option::Option::Some(FFIStatusCode::Err),
|
2 => ::std::option::Option::Some(FFIStatusCode::Internal),
|
||||||
_ => ::std::option::Option::None
|
_ => ::std::option::Option::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn values() -> &'static [Self] {
|
fn values() -> &'static [Self] {
|
||||||
static values: &'static [FFIStatusCode] = &[
|
static values: &'static [FFIStatusCode] = &[
|
||||||
FFIStatusCode::Unknown,
|
|
||||||
FFIStatusCode::Ok,
|
FFIStatusCode::Ok,
|
||||||
FFIStatusCode::Err,
|
FFIStatusCode::Err,
|
||||||
|
FFIStatusCode::Internal,
|
||||||
];
|
];
|
||||||
values
|
values
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ impl ::std::marker::Copy for FFIStatusCode {
|
|||||||
|
|
||||||
impl ::std::default::Default for FFIStatusCode {
|
impl ::std::default::Default for FFIStatusCode {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
FFIStatusCode::Unknown
|
FFIStatusCode::Ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,23 +269,23 @@ impl ::protobuf::reflect::ProtobufValue for FFIStatusCode {
|
|||||||
static file_descriptor_proto_data: &'static [u8] = b"\
|
static file_descriptor_proto_data: &'static [u8] = b"\
|
||||||
\n\x12ffi_response.proto\"K\n\x0bFFIResponse\x12\x18\n\x07payload\x18\
|
\n\x12ffi_response.proto\"K\n\x0bFFIResponse\x12\x18\n\x07payload\x18\
|
||||||
\x01\x20\x01(\x0cR\x07payload\x12\"\n\x04code\x18\x02\x20\x01(\x0e2\x0e.\
|
\x01\x20\x01(\x0cR\x07payload\x12\"\n\x04code\x18\x02\x20\x01(\x0e2\x0e.\
|
||||||
FFIStatusCodeR\x04code*-\n\rFFIStatusCode\x12\x0b\n\x07Unknown\x10\0\x12\
|
FFIStatusCodeR\x04code*.\n\rFFIStatusCode\x12\x06\n\x02Ok\x10\0\x12\x07\
|
||||||
\x06\n\x02Ok\x10\x01\x12\x07\n\x03Err\x10\x02J\xab\x02\n\x06\x12\x04\0\0\
|
\n\x03Err\x10\x01\x12\x0c\n\x08Internal\x10\x02J\xab\x02\n\x06\x12\x04\0\
|
||||||
\n\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\
|
\0\n\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\
|
||||||
\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x13\n\x0b\n\x04\x04\0\x02\0\x12\
|
\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x13\n\x0b\n\x04\x04\0\x02\0\
|
||||||
\x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\t\n\x0c\n\
|
\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\t\n\x0c\
|
||||||
\x05\x04\0\x02\0\x01\x12\x03\x03\n\x11\n\x0c\n\x05\x04\0\x02\0\x03\x12\
|
\n\x05\x04\0\x02\0\x01\x12\x03\x03\n\x11\n\x0c\n\x05\x04\0\x02\0\x03\x12\
|
||||||
\x03\x03\x14\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x1b\n\x0c\n\
|
\x03\x03\x14\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x1b\n\x0c\n\
|
||||||
\x05\x04\0\x02\x01\x06\x12\x03\x04\x04\x11\n\x0c\n\x05\x04\0\x02\x01\x01\
|
\x05\x04\0\x02\x01\x06\x12\x03\x04\x04\x11\n\x0c\n\x05\x04\0\x02\x01\x01\
|
||||||
\x12\x03\x04\x12\x16\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x19\x1a\n\
|
\x12\x03\x04\x12\x16\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x19\x1a\n\
|
||||||
\n\n\x02\x05\0\x12\x04\x06\0\n\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\
|
\n\n\x02\x05\0\x12\x04\x06\0\n\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\
|
||||||
\x12\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\
|
\x12\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\
|
||||||
\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\
|
\x01\x12\x03\x07\x04\x06\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\t\n\n\
|
||||||
\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x0b\n\x0c\n\x05\x05\0\x02\x01\
|
\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x0c\n\x0c\n\x05\x05\0\x02\x01\
|
||||||
\x01\x12\x03\x08\x04\x06\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\t\n\n\
|
\x01\x12\x03\x08\x04\x07\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\n\x0b\
|
||||||
\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x0c\n\x0c\n\x05\x05\0\x02\x02\x01\
|
\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x11\n\x0c\n\x05\x05\0\x02\x02\
|
||||||
\x12\x03\t\x04\x07\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\n\x0bb\x06pro\
|
\x01\x12\x03\t\x04\x0c\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x0f\x10b\
|
||||||
to3\
|
\x06proto3\
|
||||||
";
|
";
|
||||||
|
|
||||||
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
|
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
|
||||||
|
|||||||
@ -5,7 +5,7 @@ message FFIResponse {
|
|||||||
FFIStatusCode code = 2;
|
FFIStatusCode code = 2;
|
||||||
}
|
}
|
||||||
enum FFIStatusCode {
|
enum FFIStatusCode {
|
||||||
Unknown = 0;
|
Ok = 0;
|
||||||
Ok = 1;
|
Err = 1;
|
||||||
Err = 2;
|
Internal = 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,6 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
|
|||||||
| "FFIStatusCode"
|
| "FFIStatusCode"
|
||||||
| "UserStatus"
|
| "UserStatus"
|
||||||
| "UserEvent"
|
| "UserEvent"
|
||||||
| "ErrorCode"
|
|
||||||
=> TypeCategory::Enum,
|
=> TypeCategory::Enum,
|
||||||
|
|
||||||
"Option" => TypeCategory::Opt,
|
"Option" => TypeCategory::Opt,
|
||||||
|
|||||||
@ -114,7 +114,7 @@ impl fmt::Display for InternalError {
|
|||||||
impl Error for InternalError {
|
impl Error for InternalError {
|
||||||
fn as_response(&self) -> EventResponse {
|
fn as_response(&self) -> EventResponse {
|
||||||
let error = format!("{}", self).into_bytes();
|
let error = format!("{}", self).into_bytes();
|
||||||
ResponseBuilder::Err().data(error).build()
|
ResponseBuilder::Internal().data(error).build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,4 +37,5 @@ impl ResponseBuilder {
|
|||||||
|
|
||||||
static_response!(Ok, StatusCode::Ok);
|
static_response!(Ok, StatusCode::Ok);
|
||||||
static_response!(Err, StatusCode::Err);
|
static_response!(Err, StatusCode::Err);
|
||||||
|
static_response!(Internal, StatusCode::Internal);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,8 +10,9 @@ use std::{convert::TryFrom, fmt, fmt::Formatter};
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
|
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
|
||||||
pub enum StatusCode {
|
pub enum StatusCode {
|
||||||
Ok = 0,
|
Ok = 0,
|
||||||
Err = 1,
|
Err = 1,
|
||||||
|
Internal = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
// serde user guide: https://serde.rs/field-attrs.html
|
// serde user guide: https://serde.rs/field-attrs.html
|
||||||
@ -35,12 +36,15 @@ impl EventResponse {
|
|||||||
T: FromBytes,
|
T: FromBytes,
|
||||||
E: FromBytes,
|
E: FromBytes,
|
||||||
{
|
{
|
||||||
if self.status_code == StatusCode::Err {
|
match self.status_code {
|
||||||
let err = <Data<E>>::try_from(self.payload)?;
|
StatusCode::Ok => {
|
||||||
Ok(Err(err.into_inner()))
|
let data = <Data<T>>::try_from(self.payload)?;
|
||||||
} else {
|
Ok(Ok(data.into_inner()))
|
||||||
let data = <Data<T>>::try_from(self.payload)?;
|
},
|
||||||
Ok(Ok(data.into_inner()))
|
StatusCode::Err | StatusCode::Internal => {
|
||||||
|
let err = <Data<E>>::try_from(self.payload)?;
|
||||||
|
Ok(Err(err.into_inner()))
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,4 +23,5 @@ similar = "1.2.2"
|
|||||||
dialoguer = "0.8.0"
|
dialoguer = "0.8.0"
|
||||||
toml = "0.5.8"
|
toml = "0.5.8"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
pathdiff = "0.2.0"
|
pathdiff = "0.2.0"
|
||||||
|
itertools = "0.10"
|
||||||
@ -1,5 +1,6 @@
|
|||||||
use crate::proto::proto_info::{CrateProtoInfo, ProtoFile};
|
use crate::proto::proto_info::{CrateProtoInfo, ProtoFile};
|
||||||
use crate::util::{get_tera, read_file};
|
use crate::util::{get_tera, read_file};
|
||||||
|
use itertools::Itertools;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use tera::Context;
|
use tera::Context;
|
||||||
@ -13,6 +14,7 @@ pub struct ProtobufDeriveMeta {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
impl ProtobufDeriveMeta {
|
impl ProtobufDeriveMeta {
|
||||||
pub fn new(structs: Vec<String>, enums: Vec<String>) -> Self {
|
pub fn new(structs: Vec<String>, enums: Vec<String>) -> Self {
|
||||||
|
let enums: Vec<_> = enums.into_iter().unique().collect();
|
||||||
return ProtobufDeriveMeta {
|
return ProtobufDeriveMeta {
|
||||||
context: Context::new(),
|
context: Context::new(),
|
||||||
structs,
|
structs,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user