errors with static constructor

This commit is contained in:
appflowy 2021-09-16 12:35:55 +08:00
parent 69c8eb09c5
commit e2e47e8df0
63 changed files with 510 additions and 666 deletions

View File

@ -15,7 +15,7 @@ export 'errors.pbenum.dart';
class UserError extends $pb.GeneratedMessage { class UserError extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserError', createEmptyInstance: create) static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserError', createEmptyInstance: create)
..e<ErrorCode>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: ErrorCode.Unknown, valueOf: ErrorCode.valueOf, enumValues: ErrorCode.values) ..e<ErrorCode>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: ErrorCode.EmailIsEmpty, valueOf: ErrorCode.valueOf, enumValues: ErrorCode.values)
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'msg') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'msg')
..hasRequiredFields = false ..hasRequiredFields = false
; ;

View File

@ -10,34 +10,23 @@ import 'dart:core' as $core;
import 'package:protobuf/protobuf.dart' as $pb; import 'package:protobuf/protobuf.dart' as $pb;
class ErrorCode extends $pb.ProtobufEnum { class ErrorCode extends $pb.ProtobufEnum {
static const ErrorCode Unknown = ErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); static const ErrorCode EmailIsEmpty = ErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EmailIsEmpty');
static const ErrorCode UserDatabaseInitFailed = ErrorCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDatabaseInitFailed'); static const ErrorCode EmailFormatInvalid = ErrorCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EmailFormatInvalid');
static const ErrorCode AcquireWriteLockedFailed = ErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AcquireWriteLockedFailed'); static const ErrorCode EmailAlreadyExists = ErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EmailAlreadyExists');
static const ErrorCode AcquireReadLockedFailed = ErrorCode._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AcquireReadLockedFailed'); static const ErrorCode PasswordIsEmpty = ErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordIsEmpty');
static const ErrorCode UserDatabaseDidNotMatch = ErrorCode._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDatabaseDidNotMatch'); static const ErrorCode PasswordTooLong = ErrorCode._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordTooLong');
static const ErrorCode EmailIsEmpty = ErrorCode._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EmailIsEmpty'); static const ErrorCode PasswordContainsForbidCharacters = ErrorCode._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordContainsForbidCharacters');
static const ErrorCode EmailFormatInvalid = ErrorCode._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EmailFormatInvalid'); static const ErrorCode PasswordFormatInvalid = ErrorCode._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordFormatInvalid');
static const ErrorCode EmailAlreadyExists = ErrorCode._(22, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EmailAlreadyExists'); static const ErrorCode PasswordNotMatch = ErrorCode._(14, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordNotMatch');
static const ErrorCode PasswordIsEmpty = ErrorCode._(30, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordIsEmpty'); static const ErrorCode UserNameTooLong = ErrorCode._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNameTooLong');
static const ErrorCode PasswordTooLong = ErrorCode._(31, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordTooLong'); static const ErrorCode UserNameContainForbiddenCharacters = ErrorCode._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNameContainForbiddenCharacters');
static const ErrorCode PasswordContainsForbidCharacters = ErrorCode._(32, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordContainsForbidCharacters'); static const ErrorCode UserNameIsEmpty = ErrorCode._(22, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNameIsEmpty');
static const ErrorCode PasswordFormatInvalid = ErrorCode._(33, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordFormatInvalid'); static const ErrorCode UserIdInvalid = ErrorCode._(23, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserIdInvalid');
static const ErrorCode PasswordNotMatch = ErrorCode._(34, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordNotMatch'); static const ErrorCode UserUnauthorized = ErrorCode._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized');
static const ErrorCode UserNameTooLong = ErrorCode._(40, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNameTooLong'); static const ErrorCode UserNotExist = ErrorCode._(25, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNotExist');
static const ErrorCode ContainForbiddenCharacters = ErrorCode._(41, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ContainForbiddenCharacters');
static const ErrorCode UserNameIsEmpty = ErrorCode._(42, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNameIsEmpty');
static const ErrorCode UserWorkspaceInvalid = ErrorCode._(50, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserWorkspaceInvalid');
static const ErrorCode UserIdInvalid = ErrorCode._(51, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserIdInvalid');
static const ErrorCode UserUnauthorized = ErrorCode._(54, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized');
static const ErrorCode UserNotExist = ErrorCode._(55, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNotExist');
static const ErrorCode InternalError = ErrorCode._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'InternalError'); static const ErrorCode InternalError = ErrorCode._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'InternalError');
static const $core.List<ErrorCode> values = <ErrorCode> [ static const $core.List<ErrorCode> values = <ErrorCode> [
Unknown,
UserDatabaseInitFailed,
AcquireWriteLockedFailed,
AcquireReadLockedFailed,
UserDatabaseDidNotMatch,
EmailIsEmpty, EmailIsEmpty,
EmailFormatInvalid, EmailFormatInvalid,
EmailAlreadyExists, EmailAlreadyExists,
@ -47,9 +36,8 @@ class ErrorCode extends $pb.ProtobufEnum {
PasswordFormatInvalid, PasswordFormatInvalid,
PasswordNotMatch, PasswordNotMatch,
UserNameTooLong, UserNameTooLong,
ContainForbiddenCharacters, UserNameContainForbiddenCharacters,
UserNameIsEmpty, UserNameIsEmpty,
UserWorkspaceInvalid,
UserIdInvalid, UserIdInvalid,
UserUnauthorized, UserUnauthorized,
UserNotExist, UserNotExist,

View File

@ -12,32 +12,26 @@ import 'dart:typed_data' as $typed_data;
const ErrorCode$json = const { const ErrorCode$json = const {
'1': 'ErrorCode', '1': 'ErrorCode',
'2': const [ '2': const [
const {'1': 'Unknown', '2': 0}, const {'1': 'EmailIsEmpty', '2': 0},
const {'1': 'UserDatabaseInitFailed', '2': 1}, const {'1': 'EmailFormatInvalid', '2': 1},
const {'1': 'AcquireWriteLockedFailed', '2': 2}, const {'1': 'EmailAlreadyExists', '2': 2},
const {'1': 'AcquireReadLockedFailed', '2': 3}, const {'1': 'PasswordIsEmpty', '2': 10},
const {'1': 'UserDatabaseDidNotMatch', '2': 4}, const {'1': 'PasswordTooLong', '2': 11},
const {'1': 'EmailIsEmpty', '2': 20}, const {'1': 'PasswordContainsForbidCharacters', '2': 12},
const {'1': 'EmailFormatInvalid', '2': 21}, const {'1': 'PasswordFormatInvalid', '2': 13},
const {'1': 'EmailAlreadyExists', '2': 22}, const {'1': 'PasswordNotMatch', '2': 14},
const {'1': 'PasswordIsEmpty', '2': 30}, const {'1': 'UserNameTooLong', '2': 20},
const {'1': 'PasswordTooLong', '2': 31}, const {'1': 'UserNameContainForbiddenCharacters', '2': 21},
const {'1': 'PasswordContainsForbidCharacters', '2': 32}, const {'1': 'UserNameIsEmpty', '2': 22},
const {'1': 'PasswordFormatInvalid', '2': 33}, const {'1': 'UserIdInvalid', '2': 23},
const {'1': 'PasswordNotMatch', '2': 34}, const {'1': 'UserUnauthorized', '2': 24},
const {'1': 'UserNameTooLong', '2': 40}, const {'1': 'UserNotExist', '2': 25},
const {'1': 'ContainForbiddenCharacters', '2': 41},
const {'1': 'UserNameIsEmpty', '2': 42},
const {'1': 'UserWorkspaceInvalid', '2': 50},
const {'1': 'UserIdInvalid', '2': 51},
const {'1': 'UserUnauthorized', '2': 54},
const {'1': 'UserNotExist', '2': 55},
const {'1': 'InternalError', '2': 100}, const {'1': 'InternalError', '2': 100},
], ],
}; };
/// Descriptor for `ErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. /// Descriptor for `ErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List errorCodeDescriptor = $convert.base64Decode('CglFcnJvckNvZGUSCwoHVW5rbm93bhAAEhoKFlVzZXJEYXRhYmFzZUluaXRGYWlsZWQQARIcChhBY3F1aXJlV3JpdGVMb2NrZWRGYWlsZWQQAhIbChdBY3F1aXJlUmVhZExvY2tlZEZhaWxlZBADEhsKF1VzZXJEYXRhYmFzZURpZE5vdE1hdGNoEAQSEAoMRW1haWxJc0VtcHR5EBQSFgoSRW1haWxGb3JtYXRJbnZhbGlkEBUSFgoSRW1haWxBbHJlYWR5RXhpc3RzEBYSEwoPUGFzc3dvcmRJc0VtcHR5EB4SEwoPUGFzc3dvcmRUb29Mb25nEB8SJAogUGFzc3dvcmRDb250YWluc0ZvcmJpZENoYXJhY3RlcnMQIBIZChVQYXNzd29yZEZvcm1hdEludmFsaWQQIRIUChBQYXNzd29yZE5vdE1hdGNoECISEwoPVXNlck5hbWVUb29Mb25nECgSHgoaQ29udGFpbkZvcmJpZGRlbkNoYXJhY3RlcnMQKRITCg9Vc2VyTmFtZUlzRW1wdHkQKhIYChRVc2VyV29ya3NwYWNlSW52YWxpZBAyEhEKDVVzZXJJZEludmFsaWQQMxIUChBVc2VyVW5hdXRob3JpemVkEDYSEAoMVXNlck5vdEV4aXN0EDcSEQoNSW50ZXJuYWxFcnJvchBk'); final $typed_data.Uint8List errorCodeDescriptor = $convert.base64Decode('CglFcnJvckNvZGUSEAoMRW1haWxJc0VtcHR5EAASFgoSRW1haWxGb3JtYXRJbnZhbGlkEAESFgoSRW1haWxBbHJlYWR5RXhpc3RzEAISEwoPUGFzc3dvcmRJc0VtcHR5EAoSEwoPUGFzc3dvcmRUb29Mb25nEAsSJAogUGFzc3dvcmRDb250YWluc0ZvcmJpZENoYXJhY3RlcnMQDBIZChVQYXNzd29yZEZvcm1hdEludmFsaWQQDRIUChBQYXNzd29yZE5vdE1hdGNoEA4SEwoPVXNlck5hbWVUb29Mb25nEBQSJgoiVXNlck5hbWVDb250YWluRm9yYmlkZGVuQ2hhcmFjdGVycxAVEhMKD1VzZXJOYW1lSXNFbXB0eRAWEhEKDVVzZXJJZEludmFsaWQQFxIUChBVc2VyVW5hdXRob3JpemVkEBgSEAoMVXNlck5vdEV4aXN0EBkSEQoNSW50ZXJuYWxFcnJvchBk');
@$core.Deprecated('Use userErrorDescriptor instead') @$core.Deprecated('Use userErrorDescriptor instead')
const UserError$json = const { const UserError$json = const {
'1': 'UserError', '1': 'UserError',

View File

@ -15,7 +15,7 @@ export 'errors.pbenum.dart';
class WorkspaceError extends $pb.GeneratedMessage { class WorkspaceError extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'WorkspaceError', createEmptyInstance: create) static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'WorkspaceError', createEmptyInstance: create)
..e<ErrorCode>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: ErrorCode.Unknown, valueOf: ErrorCode.valueOf, enumValues: ErrorCode.values) ..e<ErrorCode>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'code', $pb.PbFieldType.OE, defaultOrMaker: ErrorCode.WorkspaceNameInvalid, valueOf: ErrorCode.valueOf, enumValues: ErrorCode.values)
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'msg') ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'msg')
..hasRequiredFields = false ..hasRequiredFields = false
; ;

View File

@ -10,12 +10,10 @@ import 'dart:core' as $core;
import 'package:protobuf/protobuf.dart' as $pb; import 'package:protobuf/protobuf.dart' as $pb;
class ErrorCode extends $pb.ProtobufEnum { class ErrorCode extends $pb.ProtobufEnum {
static const ErrorCode Unknown = ErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); static const ErrorCode WorkspaceNameInvalid = ErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceNameInvalid');
static const ErrorCode WorkspaceNameInvalid = ErrorCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceNameInvalid'); static const ErrorCode WorkspaceIdInvalid = ErrorCode._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceIdInvalid');
static const ErrorCode WorkspaceIdInvalid = ErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceIdInvalid'); static const ErrorCode AppColorStyleInvalid = ErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppColorStyleInvalid');
static const ErrorCode AppColorStyleInvalid = ErrorCode._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppColorStyleInvalid'); static const ErrorCode WorkspaceDescInvalid = ErrorCode._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceDescInvalid');
static const ErrorCode WorkspaceDescInvalid = ErrorCode._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceDescInvalid');
static const ErrorCode CurrentWorkspaceNotFound = ErrorCode._(5, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CurrentWorkspaceNotFound');
static const ErrorCode AppIdInvalid = ErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppIdInvalid'); static const ErrorCode AppIdInvalid = ErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppIdInvalid');
static const ErrorCode AppNameInvalid = ErrorCode._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppNameInvalid'); static const ErrorCode AppNameInvalid = ErrorCode._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppNameInvalid');
static const ErrorCode ViewNameInvalid = ErrorCode._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewNameInvalid'); static const ErrorCode ViewNameInvalid = ErrorCode._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewNameInvalid');
@ -23,18 +21,15 @@ class ErrorCode extends $pb.ProtobufEnum {
static const ErrorCode ViewIdInvalid = ErrorCode._(22, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewIdInvalid'); static const ErrorCode ViewIdInvalid = ErrorCode._(22, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewIdInvalid');
static const ErrorCode ViewDescInvalid = ErrorCode._(23, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewDescInvalid'); static const ErrorCode ViewDescInvalid = ErrorCode._(23, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewDescInvalid');
static const ErrorCode ViewDataInvalid = ErrorCode._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewDataInvalid'); static const ErrorCode ViewDataInvalid = ErrorCode._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewDataInvalid');
static const ErrorCode UserIdIsEmpty = ErrorCode._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserIdIsEmpty'); static const ErrorCode UserUnauthorized = ErrorCode._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized');
static const ErrorCode UserUnauthorized = ErrorCode._(101, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized');
static const ErrorCode InternalError = ErrorCode._(1000, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'InternalError'); static const ErrorCode InternalError = ErrorCode._(1000, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'InternalError');
static const ErrorCode RecordNotFound = ErrorCode._(1001, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'RecordNotFound'); static const ErrorCode RecordNotFound = ErrorCode._(1001, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'RecordNotFound');
static const $core.List<ErrorCode> values = <ErrorCode> [ static const $core.List<ErrorCode> values = <ErrorCode> [
Unknown,
WorkspaceNameInvalid, WorkspaceNameInvalid,
WorkspaceIdInvalid, WorkspaceIdInvalid,
AppColorStyleInvalid, AppColorStyleInvalid,
WorkspaceDescInvalid, WorkspaceDescInvalid,
CurrentWorkspaceNotFound,
AppIdInvalid, AppIdInvalid,
AppNameInvalid, AppNameInvalid,
ViewNameInvalid, ViewNameInvalid,
@ -42,7 +37,6 @@ class ErrorCode extends $pb.ProtobufEnum {
ViewIdInvalid, ViewIdInvalid,
ViewDescInvalid, ViewDescInvalid,
ViewDataInvalid, ViewDataInvalid,
UserIdIsEmpty,
UserUnauthorized, UserUnauthorized,
InternalError, InternalError,
RecordNotFound, RecordNotFound,

View File

@ -12,12 +12,10 @@ import 'dart:typed_data' as $typed_data;
const ErrorCode$json = const { const ErrorCode$json = const {
'1': 'ErrorCode', '1': 'ErrorCode',
'2': const [ '2': const [
const {'1': 'Unknown', '2': 0}, const {'1': 'WorkspaceNameInvalid', '2': 0},
const {'1': 'WorkspaceNameInvalid', '2': 1}, const {'1': 'WorkspaceIdInvalid', '2': 1},
const {'1': 'WorkspaceIdInvalid', '2': 2}, const {'1': 'AppColorStyleInvalid', '2': 2},
const {'1': 'AppColorStyleInvalid', '2': 3}, const {'1': 'WorkspaceDescInvalid', '2': 3},
const {'1': 'WorkspaceDescInvalid', '2': 4},
const {'1': 'CurrentWorkspaceNotFound', '2': 5},
const {'1': 'AppIdInvalid', '2': 10}, const {'1': 'AppIdInvalid', '2': 10},
const {'1': 'AppNameInvalid', '2': 11}, const {'1': 'AppNameInvalid', '2': 11},
const {'1': 'ViewNameInvalid', '2': 20}, const {'1': 'ViewNameInvalid', '2': 20},
@ -25,15 +23,14 @@ const ErrorCode$json = const {
const {'1': 'ViewIdInvalid', '2': 22}, const {'1': 'ViewIdInvalid', '2': 22},
const {'1': 'ViewDescInvalid', '2': 23}, const {'1': 'ViewDescInvalid', '2': 23},
const {'1': 'ViewDataInvalid', '2': 24}, const {'1': 'ViewDataInvalid', '2': 24},
const {'1': 'UserIdIsEmpty', '2': 100}, const {'1': 'UserUnauthorized', '2': 100},
const {'1': 'UserUnauthorized', '2': 101},
const {'1': 'InternalError', '2': 1000}, const {'1': 'InternalError', '2': 1000},
const {'1': 'RecordNotFound', '2': 1001}, const {'1': 'RecordNotFound', '2': 1001},
], ],
}; };
/// Descriptor for `ErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. /// Descriptor for `ErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List errorCodeDescriptor = $convert.base64Decode('CglFcnJvckNvZGUSCwoHVW5rbm93bhAAEhgKFFdvcmtzcGFjZU5hbWVJbnZhbGlkEAESFgoSV29ya3NwYWNlSWRJbnZhbGlkEAISGAoUQXBwQ29sb3JTdHlsZUludmFsaWQQAxIYChRXb3Jrc3BhY2VEZXNjSW52YWxpZBAEEhwKGEN1cnJlbnRXb3Jrc3BhY2VOb3RGb3VuZBAFEhAKDEFwcElkSW52YWxpZBAKEhIKDkFwcE5hbWVJbnZhbGlkEAsSEwoPVmlld05hbWVJbnZhbGlkEBQSGAoUVmlld1RodW1ibmFpbEludmFsaWQQFRIRCg1WaWV3SWRJbnZhbGlkEBYSEwoPVmlld0Rlc2NJbnZhbGlkEBcSEwoPVmlld0RhdGFJbnZhbGlkEBgSEQoNVXNlcklkSXNFbXB0eRBkEhQKEFVzZXJVbmF1dGhvcml6ZWQQZRISCg1JbnRlcm5hbEVycm9yEOgHEhMKDlJlY29yZE5vdEZvdW5kEOkH'); final $typed_data.Uint8List errorCodeDescriptor = $convert.base64Decode('CglFcnJvckNvZGUSGAoUV29ya3NwYWNlTmFtZUludmFsaWQQABIWChJXb3Jrc3BhY2VJZEludmFsaWQQARIYChRBcHBDb2xvclN0eWxlSW52YWxpZBACEhgKFFdvcmtzcGFjZURlc2NJbnZhbGlkEAMSEAoMQXBwSWRJbnZhbGlkEAoSEgoOQXBwTmFtZUludmFsaWQQCxITCg9WaWV3TmFtZUludmFsaWQQFBIYChRWaWV3VGh1bWJuYWlsSW52YWxpZBAVEhEKDVZpZXdJZEludmFsaWQQFhITCg9WaWV3RGVzY0ludmFsaWQQFxITCg9WaWV3RGF0YUludmFsaWQQGBIUChBVc2VyVW5hdXRob3JpemVkEGQSEgoNSW50ZXJuYWxFcnJvchDoBxITCg5SZWNvcmROb3RGb3VuZBDpBw==');
@$core.Deprecated('Use workspaceErrorDescriptor instead') @$core.Deprecated('Use workspaceErrorDescriptor instead')
const WorkspaceError$json = const { const WorkspaceError$json = const {
'1': 'WorkspaceError', '1': 'WorkspaceError',

View File

@ -69,9 +69,9 @@ async fn create_view(transaction: &mut DBTransaction<'_>, app: &App) -> Result<V
cached_size: Default::default(), cached_size: Default::default(),
}; };
let name = "DefaultView".to_string(); let _name = "DefaultView".to_string();
let desc = "View created by AppFlowy Server".to_string(); let _desc = "View created by AppFlowy Server".to_string();
let thumbnail = "http://1.png".to_string(); let _thumbnail = "http://1.png".to_string();
let view = create_view_with_transaction(transaction, params).await?; let view = create_view_with_transaction(transaction, params).await?;

View File

@ -4,7 +4,7 @@ use backend::{
}; };
use flowy_document::{ use flowy_document::{
entities::doc::{Doc, QueryDocParams, SaveDocParams}, entities::doc::{Doc, QueryDocParams},
prelude::*, prelude::*,
}; };
use flowy_user::{errors::UserError, prelude::*}; use flowy_user::{errors::UserError, prelude::*};

View File

@ -1,4 +1,2 @@
mod model; mod model;
pub use model::*; pub use model::*;

View File

@ -1,7 +1,7 @@
// Auto-generated, do not edit // Auto-generated, do not edit
mod ffi_response; mod ffi_response;
pub use ffi_response::*; pub use ffi_response::*;
mod ffi_request; mod ffi_request;
pub use ffi_request::*; pub use ffi_request::*;

View File

@ -58,10 +58,4 @@ table! {
} }
} }
allow_tables_to_appear_in_same_query!( allow_tables_to_appear_in_same_query!(app_table, doc_table, user_table, view_table, workspace_table,);
app_table,
doc_table,
user_table,
view_table,
workspace_table,
);

View File

@ -71,8 +71,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
| "UserProfile" | "UserProfile"
| "UpdateUserRequest" | "UpdateUserRequest"
| "UpdateUserParams" | "UpdateUserParams"
| "UserError" | "UserError" => TypeCategory::Protobuf,
=> TypeCategory::Protobuf,
"ViewType" "ViewType"
| "WorkspaceEvent" | "WorkspaceEvent"
| "ErrorCode" | "ErrorCode"
@ -81,8 +80,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
| "FFIStatusCode" | "FFIStatusCode"
| "UserStatus" | "UserStatus"
| "UserEvent" | "UserEvent"
| "UserObservable" | "UserObservable" => TypeCategory::Enum,
=> TypeCategory::Enum,
"Option" => TypeCategory::Opt, "Option" => TypeCategory::Opt,
_ => TypeCategory::Primitive, _ => TypeCategory::Primitive,

View File

@ -5,7 +5,7 @@ use std::sync::Once;
#[allow(dead_code)] #[allow(dead_code)]
pub fn setup_env() { pub fn setup_env() {
static INIT: Once = Once::new(); static INIT: Once = Once::new();
INIT.call_once(|| env_logger::init()); (|| env_logger::init());
} }
pub fn init_dispatch<F>(module_factory: F) -> EventDispatch pub fn init_dispatch<F>(module_factory: F) -> EventDispatch

View File

@ -1,5 +1,4 @@
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use std::convert::TryInto;
#[derive(ProtoBuf, Default, Debug, Clone)] #[derive(ProtoBuf, Default, Debug, Clone)]
pub struct CreateDocParams { pub struct CreateDocParams {

View File

@ -14,10 +14,39 @@ pub struct DocError {
pub msg: String, pub msg: String,
} }
macro_rules! static_doc_error {
($name:ident, $status:expr) => {
#[allow(non_snake_case, missing_docs)]
pub fn $name() -> DocError {
DocError {
code: $status,
msg: format!("{}", $status),
}
}
};
}
impl DocError { impl DocError {
fn new(code: ErrorCode, msg: &str) -> Self { Self { code, msg: msg.to_owned() } } fn new(code: ErrorCode, msg: &str) -> Self { Self { code, msg: msg.to_owned() } }
pub fn context<T: Debug>(mut self, error: T) -> Self {
self.msg = format!("{:?}", error);
self
}
pub fn is_record_not_found(&self) -> bool { self.code == ErrorCode::DocNotfound } pub fn is_record_not_found(&self) -> bool { self.code == ErrorCode::DocNotfound }
static_doc_error!(id_invalid, ErrorCode::DocIdInvalid);
static_doc_error!(internal, ErrorCode::InternalError);
static_doc_error!(not_found, ErrorCode::DocNotfound);
static_doc_error!(unauthorized, ErrorCode::UserUnauthorized);
}
pub fn internal_error<T>(e: T) -> DocError
where
T: std::fmt::Debug,
{
DocError::internal().context(e)
} }
#[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)] #[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)]
@ -42,14 +71,14 @@ impl std::default::Default for ErrorCode {
impl std::convert::From<flowy_database::Error> for DocError { impl std::convert::From<flowy_database::Error> for DocError {
fn from(error: flowy_database::Error) -> Self { fn from(error: flowy_database::Error) -> Self {
match error { match error {
flowy_database::Error::NotFound => ErrorBuilder::new(ErrorCode::DocNotfound).error(error).build(), flowy_database::Error::NotFound => DocError::not_found().context(error),
_ => ErrorBuilder::new(ErrorCode::InternalError).error(error).build(), _ => DocError::internal().context(error),
} }
} }
} }
impl std::convert::From<flowy_ot::errors::OTError> for DocError { impl std::convert::From<flowy_ot::errors::OTError> for DocError {
fn from(error: flowy_ot::errors::OTError) -> Self { ErrorBuilder::new(ErrorCode::InternalError).error(error).build() } fn from(error: flowy_ot::errors::OTError) -> Self { DocError::internal().context(error) }
} }
// impl std::convert::From<::r2d2::Error> for DocError { // impl std::convert::From<::r2d2::Error> for DocError {
@ -63,11 +92,12 @@ impl std::convert::From<flowy_ot::errors::OTError> for DocError {
impl std::convert::From<flowy_net::errors::ServerError> for DocError { impl std::convert::From<flowy_net::errors::ServerError> for DocError {
fn from(error: ServerError) -> Self { fn from(error: ServerError) -> Self {
let code = server_error_to_doc_error(error.code); let code = server_error_to_doc_error(error.code);
ErrorBuilder::new(code).error(error.msg).build() DocError::new(code, &error.msg)
} }
} }
use flowy_net::errors::ErrorCode as ServerErrorCode; use flowy_net::errors::ErrorCode as ServerErrorCode;
use std::fmt::Debug;
fn server_error_to_doc_error(code: ServerErrorCode) -> ErrorCode { fn server_error_to_doc_error(code: ServerErrorCode) -> ErrorCode {
match code { match code {
@ -87,8 +117,3 @@ impl flowy_dispatch::Error for DocError {
impl fmt::Display for DocError { impl fmt::Display for DocError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}: {}", &self.code, &self.msg) } fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}: {}", &self.code, &self.msg) }
} }
pub type ErrorBuilder = flowy_infra::errors::Builder<ErrorCode, DocError>;
impl flowy_infra::errors::Build<ErrorCode> for DocError {
fn build(code: ErrorCode, msg: String) -> Self { DocError::new(code, &msg) }
}

View File

@ -9,9 +9,9 @@ use crate::{
}; };
use diesel::SqliteConnection; use diesel::SqliteConnection;
use flowy_database::ConnectionPool; use flowy_database::ConnectionPool;
use flowy_ot::client::Document;
use crate::errors::internal_error;
use std::sync::Arc; use std::sync::Arc;
use tokio::sync::RwLock;
pub trait DocumentUser: Send + Sync { pub trait DocumentUser: Send + Sync {
fn user_doc_dir(&self) -> Result<String, DocError>; fn user_doc_dir(&self) -> Result<String, DocError>;
@ -51,7 +51,7 @@ impl FlowyDocument {
} }
pub async fn update(&self, params: SaveDocParams, pool: Arc<ConnectionPool>) -> Result<(), DocError> { pub async fn update(&self, params: SaveDocParams, pool: Arc<ConnectionPool>) -> Result<(), DocError> {
let _ = self.controller.update(params, &*pool.get().unwrap())?; let _ = self.controller.update(params, &*pool.get().map_err(internal_error)?)?;
Ok(()) Ok(())
} }

View File

@ -1,4 +1,2 @@
mod model; mod model;
pub use model::*; pub use model::*;

View File

@ -1,13 +1,13 @@
// Auto-generated, do not edit // Auto-generated, do not edit
mod observable; mod observable;
pub use observable::*; pub use observable::*;
mod errors; mod errors;
pub use errors::*; pub use errors::*;
mod event; mod event;
pub use event::*; pub use event::*;
mod doc; mod doc;
pub use doc::*; pub use doc::*;

View File

@ -1,10 +1,6 @@
use crate::errors::{DocError, ErrorBuilder, ErrorCode}; use crate::errors::DocError;
use dashmap::DashMap; use dashmap::DashMap;
use flowy_ot::{ use flowy_ot::{client::Document, core::Delta, errors::OTError};
client::{Document, FlowyDoc},
core::Delta,
errors::OTError,
};
use std::convert::TryInto; use std::convert::TryInto;
use tokio::sync::RwLock; use tokio::sync::RwLock;
@ -65,7 +61,7 @@ impl DocCache {
match self.inner.get(&doc_id) { match self.inner.get(&doc_id) {
None => Err(doc_not_found()), None => Err(doc_not_found()),
Some(doc_info) => { Some(doc_info) => {
let mut write_guard = doc_info.read().await; let write_guard = doc_info.read().await;
let doc = &(*write_guard).document; let doc = &(*write_guard).document;
Ok(Some(doc.to_json())) Ok(Some(doc.to_json()))
}, },
@ -82,8 +78,4 @@ impl DocCache {
} }
} }
fn doc_not_found() -> DocError { fn doc_not_found() -> DocError { DocError::not_found().context("Doc is close or you should call open first") }
ErrorBuilder::new(ErrorCode::DocNotfound)
.msg("Doc is close or you should call open first")
.build()
}

View File

@ -1,12 +1,13 @@
use crate::{ use crate::{
entities::doc::{CreateDocParams, Doc, QueryDocParams, SaveDocParams}, entities::doc::{CreateDocParams, Doc, QueryDocParams, SaveDocParams},
errors::{DocError, ErrorBuilder, ErrorCode}, errors::DocError,
module::DocumentUser, module::DocumentUser,
services::server::Server, services::server::Server,
sql_tables::doc::{DocTable, DocTableChangeset, DocTableSql}, sql_tables::doc::{DocTable, DocTableChangeset, DocTableSql},
}; };
use flowy_database::{ConnectionPool, SqliteConnection}; use flowy_database::{ConnectionPool, SqliteConnection};
use crate::errors::internal_error;
use std::sync::Arc; use std::sync::Arc;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
@ -86,10 +87,10 @@ impl DocController {
Ok(tokio::spawn(async move { Ok(tokio::spawn(async move {
match server.read_doc(&token, params).await? { match server.read_doc(&token, params).await? {
None => Err(ErrorBuilder::new(ErrorCode::DocNotfound).build()), None => Err(DocError::not_found()),
Some(doc) => { Some(doc) => {
let doc_table = DocTable::new(doc.clone()); let doc_table = DocTable::new(doc.clone());
let _ = sql.create_doc_table(doc_table, &*(pool.get().unwrap()))?; let _ = sql.create_doc_table(doc_table, &*(pool.get().map_err(internal_error)?))?;
// TODO: notify // TODO: notify
Ok(doc) Ok(doc)
}, },
@ -101,7 +102,7 @@ impl DocController {
async fn sync_read_doc_from_server(&self, params: QueryDocParams) -> Result<Doc, DocError> { async fn sync_read_doc_from_server(&self, params: QueryDocParams) -> Result<Doc, DocError> {
let token = self.user.token()?; let token = self.user.token()?;
match self.server.read_doc(&token, params).await? { match self.server.read_doc(&token, params).await? {
None => Err(ErrorBuilder::new(ErrorCode::DocNotfound).build()), None => Err(DocError::not_found()),
Some(doc) => Ok(doc), Some(doc) => Ok(doc),
} }
} }
@ -123,7 +124,7 @@ impl DocController {
} }
fn _open(&self, params: QueryDocParams, pool: Arc<ConnectionPool>) -> Result<Doc, DocError> { fn _open(&self, params: QueryDocParams, pool: Arc<ConnectionPool>) -> Result<Doc, DocError> {
let doc_table = self.sql.read_doc_table(&params.doc_id, &*(pool.get().unwrap()))?; let doc_table = self.sql.read_doc_table(&params.doc_id, &*(pool.get().map_err(internal_error)?))?;
let doc: Doc = doc_table.into(); let doc: Doc = doc_table.into();
let _ = self.read_doc_from_server(params, pool.clone())?; let _ = self.read_doc_from_server(params, pool.clone())?;
Ok(doc) Ok(doc)
@ -138,10 +139,3 @@ impl DocController {
} }
} }
} }
fn internal_error<T>(e: T) -> DocError
where
T: std::fmt::Debug,
{
ErrorBuilder::new(ErrorCode::InternalError).error(e).build()
}

View File

@ -3,7 +3,7 @@ use std::{fmt::Debug, marker::PhantomData};
pub trait Build<C> { pub trait Build<C> {
fn build(code: C, msg: String) -> Self; fn build(code: C, msg: String) -> Self;
} }
#[allow(dead_code)]
pub struct Builder<C, O> { pub struct Builder<C, O> {
pub code: C, pub code: C,
pub msg: Option<String>, pub msg: Option<String>,

View File

@ -1,4 +1,2 @@
mod model; mod model;
pub use model::*; pub use model::*;

View File

@ -1,4 +1,4 @@
// Auto-generated, do not edit // Auto-generated, do not edit
mod kv; mod kv;
pub use kv::*; pub use kv::*;

View File

@ -49,7 +49,7 @@
// return // return
// Err(de::Error::duplicate_field("data")); } // Err(de::Error::duplicate_field("data")); }
// data = match // data = match
// MapAccess::next_value::<DeserializeWith<T>>(&mut map) { // MapAccess::next_value::<DeserializeWith<T>>(&mut map) {
// Ok(wrapper) => wrapper.value, Err(err) => // Ok(wrapper) => wrapper.value, Err(err) =>
// return Err(err), }; // return Err(err), };
// }, // },
@ -58,7 +58,7 @@
// } // }
// let msg = msg.ok_or_else(|| // let msg = msg.ok_or_else(||
// de::Error::missing_field("msg"))?; let code = // de::Error::missing_field("msg"))?; let code =
// code.ok_or_else(|| de::Error::missing_field("code"))?; // code.ok_or_else(|| de::Error::missing_field("code"))?;
// Ok(Self::Value::new(data, msg, code)) } // Ok(Self::Value::new(data, msg, code)) }
// } // }
// const FIELDS: &'static [&'static str] = &["msg", "code", "data"]; // const FIELDS: &'static [&'static str] = &["msg", "code", "data"];

View File

@ -1,4 +1,2 @@
mod model; mod model;
pub use model::*; pub use model::*;

View File

@ -1,4 +1,4 @@
// Auto-generated, do not edit // Auto-generated, do not edit
mod subject; mod subject;
pub use subject::*; pub use subject::*;

View File

@ -2,7 +2,7 @@
use crate::{block_attribute, core::Attributes, ignore_attribute, inline_attribute, list_attribute}; use crate::{block_attribute, core::Attributes, ignore_attribute, inline_attribute, list_attribute};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::{collections::HashSet, fmt, fmt::Formatter, iter::FromIterator}; use std::{collections::HashSet, fmt, fmt::Formatter, iter::FromIterator};
use strum_macros::Display; use strum_macros::Display;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -1,6 +1,6 @@
#[rustfmt::skip] #[rustfmt::skip]
use crate::core::AttributeValue; use crate::core::AttributeValue;
use crate::core::{Attribute, AttributeKey, Attributes}; use crate::core::{AttributeKey, Attributes};
use serde::{ use serde::{
de, de,
de::{MapAccess, Visitor}, de::{MapAccess, Visitor},
@ -10,7 +10,7 @@ use serde::{
Serialize, Serialize,
Serializer, Serializer,
}; };
use std::{collections::HashMap, fmt, marker::PhantomData, str::ParseBoolError}; use std::fmt;
impl Serialize for Attributes { impl Serialize for Attributes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>

View File

@ -1,7 +1,4 @@
use flowy_document::{ use flowy_document::{errors::DocError, module::DocumentUser};
errors::{DocError, ErrorBuilder, ErrorCode},
module::DocumentUser,
};
use flowy_user::services::user::UserSession; use flowy_user::services::user::UserSession;
use std::{path::Path, sync::Arc}; use std::{path::Path, sync::Arc};
@ -12,10 +9,7 @@ pub struct EditorUserImpl {
impl DocumentUser for EditorUserImpl { impl DocumentUser for EditorUserImpl {
fn user_doc_dir(&self) -> Result<String, DocError> { fn user_doc_dir(&self) -> Result<String, DocError> {
let dir = self let dir = self.user_session.user_dir().map_err(|e| DocError::unauthorized().context(e))?;
.user_session
.user_dir()
.map_err(|e| ErrorBuilder::new(ErrorCode::UserUnauthorized).error(e).build())?;
let doc_dir = format!("{}/doc", dir); let doc_dir = format!("{}/doc", dir);
if !Path::new(&doc_dir).exists() { if !Path::new(&doc_dir).exists() {
@ -25,15 +19,7 @@ impl DocumentUser for EditorUserImpl {
Ok(doc_dir) Ok(doc_dir)
} }
fn user_id(&self) -> Result<String, DocError> { fn user_id(&self) -> Result<String, DocError> { self.user_session.user_id().map_err(|e| DocError::internal().context(e)) }
self.user_session
.user_id()
.map_err(|e| ErrorBuilder::new(ErrorCode::InternalError).error(e).build())
}
fn token(&self) -> Result<String, DocError> { fn token(&self) -> Result<String, DocError> { self.user_session.token().map_err(|e| DocError::internal().context(e)) }
self.user_session
.token()
.map_err(|e| ErrorBuilder::new(ErrorCode::InternalError).error(e).build())
}
} }

View File

@ -1,7 +1,7 @@
use flowy_database::ConnectionPool; use flowy_database::ConnectionPool;
use flowy_user::services::user::UserSession; use flowy_user::services::user::UserSession;
use flowy_workspace::{ use flowy_workspace::{
errors::{ErrorBuilder, ErrorCode, WorkspaceError}, errors::WorkspaceError,
module::{WorkspaceDatabase, WorkspaceUser}, module::{WorkspaceDatabase, WorkspaceUser},
}; };
use std::sync::Arc; use std::sync::Arc;
@ -11,17 +11,9 @@ pub struct WorkspaceUserImpl {
} }
impl WorkspaceUser for WorkspaceUserImpl { impl WorkspaceUser for WorkspaceUserImpl {
fn user_id(&self) -> Result<String, WorkspaceError> { fn user_id(&self) -> Result<String, WorkspaceError> { self.user_session.user_id().map_err(|e| WorkspaceError::internal().context(e)) }
self.user_session
.user_id()
.map_err(|e| ErrorBuilder::new(ErrorCode::InternalError).error(e).build())
}
fn token(&self) -> Result<String, WorkspaceError> { fn token(&self) -> Result<String, WorkspaceError> { self.user_session.token().map_err(|e| WorkspaceError::internal().context(e)) }
self.user_session
.token()
.map_err(|e| ErrorBuilder::new(ErrorCode::InternalError).error(e).build())
}
} }
pub struct WorkspaceDatabaseImpl { pub struct WorkspaceDatabaseImpl {
@ -30,8 +22,6 @@ pub struct WorkspaceDatabaseImpl {
impl WorkspaceDatabase for WorkspaceDatabaseImpl { impl WorkspaceDatabase for WorkspaceDatabaseImpl {
fn db_pool(&self) -> Result<Arc<ConnectionPool>, WorkspaceError> { fn db_pool(&self) -> Result<Arc<ConnectionPool>, WorkspaceError> {
self.user_session self.user_session.db_pool().map_err(|e| WorkspaceError::internal().context(e))
.db_pool()
.map_err(|e| ErrorBuilder::new(ErrorCode::InternalError).error(e).build())
} }
} }

View File

@ -4,7 +4,7 @@ use flowy_infra::{kv::KV, uuid};
use flowy_user::{ use flowy_user::{
entities::{SignInRequest, SignUpRequest, UserProfile}, entities::{SignInRequest, SignUpRequest, UserProfile},
errors::{ErrorBuilder, ErrorCode, UserError}, errors::UserError,
event::UserEvent::{SignIn, SignOut, SignUp}, event::UserEvent::{SignIn, SignOut, SignUp},
}; };
use flowy_workspace::{ use flowy_workspace::{
@ -44,7 +44,7 @@ const DEFAULT_WORKSPACE: &'static str = "Default_Workspace";
pub(crate) fn create_default_workspace_if_need(dispatch: Arc<EventDispatch>, user_id: &str) -> Result<(), UserError> { pub(crate) fn create_default_workspace_if_need(dispatch: Arc<EventDispatch>, user_id: &str) -> Result<(), UserError> {
let key = format!("{}{}", user_id, DEFAULT_WORKSPACE); let key = format!("{}{}", user_id, DEFAULT_WORKSPACE);
if KV::get_bool(&key).unwrap_or(false) { if KV::get_bool(&key).unwrap_or(false) {
return Err(ErrorBuilder::new(ErrorCode::InternalError).build()); return Err(UserError::internal());
} }
KV::set_bool(&key, true); KV::set_bool(&key, true);
@ -58,9 +58,9 @@ pub(crate) fn create_default_workspace_if_need(dispatch: Arc<EventDispatch>, use
let request = ModuleRequest::new(CreateWorkspace).payload(payload); let request = ModuleRequest::new(CreateWorkspace).payload(payload);
let result = EventDispatch::sync_send(dispatch.clone(), request) let result = EventDispatch::sync_send(dispatch.clone(), request)
.parse::<Workspace, WorkspaceError>() .parse::<Workspace, WorkspaceError>()
.map_err(|e| ErrorBuilder::new(ErrorCode::InternalError).error(e).build())?; .map_err(|e| UserError::internal().context(e))?;
let workspace = result.map_err(|e| ErrorBuilder::new(ErrorCode::InternalError).error(e).build())?; let workspace = result.map_err(|e| UserError::internal().context(e))?;
let query: Bytes = QueryWorkspaceRequest { let query: Bytes = QueryWorkspaceRequest {
workspace_id: Some(workspace.id.clone()), workspace_id: Some(workspace.id.clone()),
} }

View File

@ -39,8 +39,8 @@ impl TryInto<SignInParams> for SignInRequest {
type Error = UserError; type Error = UserError;
fn try_into(self) -> Result<SignInParams, Self::Error> { fn try_into(self) -> Result<SignInParams, Self::Error> {
let email = UserEmail::parse(self.email).map_err(|e| ErrorBuilder::new(e).build())?; let email = UserEmail::parse(self.email).map_err(|e| UserError::code(e))?;
let password = UserPassword::parse(self.password).map_err(|e| ErrorBuilder::new(e).build())?; let password = UserPassword::parse(self.password).map_err(|e| UserError::code(e))?;
Ok(SignInParams { Ok(SignInParams {
email: email.0, email: email.0,
@ -64,9 +64,9 @@ impl TryInto<SignUpParams> for SignUpRequest {
type Error = UserError; type Error = UserError;
fn try_into(self) -> Result<SignUpParams, Self::Error> { fn try_into(self) -> Result<SignUpParams, Self::Error> {
let email = UserEmail::parse(self.email).map_err(|e| ErrorBuilder::new(e).build())?; let email = UserEmail::parse(self.email).map_err(|e| UserError::code(e))?;
let password = UserPassword::parse(self.password).map_err(|e| ErrorBuilder::new(e).build())?; let password = UserPassword::parse(self.password).map_err(|e| UserError::code(e))?;
let name = UserName::parse(self.name).map_err(|e| ErrorBuilder::new(e).build())?; let name = UserName::parse(self.name).map_err(|e| UserError::code(e))?;
Ok(SignUpParams { Ok(SignUpParams {
email: email.0, email: email.0,

View File

@ -26,7 +26,7 @@ impl UserName {
let contains_forbidden_characters = s.chars().any(|g| forbidden_characters.contains(&g)); let contains_forbidden_characters = s.chars().any(|g| forbidden_characters.contains(&g));
if contains_forbidden_characters { if contains_forbidden_characters {
return Err(ErrorCode::ContainForbiddenCharacters); return Err(ErrorCode::UserNameContainForbiddenCharacters);
} }
Ok(Self(s)) Ok(Self(s))

View File

@ -34,7 +34,7 @@ pub struct UserProfile {
use crate::{ use crate::{
entities::parser::{UserEmail, UserId, UserName, UserPassword}, entities::parser::{UserEmail, UserId, UserName, UserPassword},
errors::{ErrorBuilder, ErrorCode, UserError}, errors::UserError,
sql_tables::UserTable, sql_tables::UserTable,
}; };
use std::convert::TryInto; use std::convert::TryInto;
@ -133,23 +133,21 @@ impl TryInto<UpdateUserParams> for UpdateUserRequest {
type Error = UserError; type Error = UserError;
fn try_into(self) -> Result<UpdateUserParams, Self::Error> { fn try_into(self) -> Result<UpdateUserParams, Self::Error> {
let id = UserId::parse(self.id) let id = UserId::parse(self.id).map_err(|e| UserError::user_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::UserIdInvalid).msg(e).build())?
.0;
let name = match self.name { let name = match self.name {
None => None, None => None,
Some(name) => Some(UserName::parse(name).map_err(|e| ErrorBuilder::new(e).build())?.0), Some(name) => Some(UserName::parse(name).map_err(|e| UserError::code(e))?.0),
}; };
let email = match self.email { let email = match self.email {
None => None, None => None,
Some(email) => Some(UserEmail::parse(email).map_err(|e| ErrorBuilder::new(e).build())?.0), Some(email) => Some(UserEmail::parse(email).map_err(|e| UserError::code(e))?.0),
}; };
let password = match self.password { let password = match self.password {
None => None, None => None,
Some(password) => Some(UserPassword::parse(password).map_err(|e| ErrorBuilder::new(e).build())?.0), Some(password) => Some(UserPassword::parse(password).map_err(|e| UserError::code(e))?.0),
}; };
Ok(UpdateUserParams { id, name, email, password }) Ok(UpdateUserParams { id, name, email, password })

View File

@ -14,86 +14,111 @@ pub struct UserError {
pub msg: String, pub msg: String,
} }
macro_rules! static_user_error {
($name:ident, $status:expr) => {
#[allow(non_snake_case, missing_docs)]
pub fn $name() -> UserError {
UserError {
code: $status,
msg: format!("{}", $status),
}
}
};
}
impl UserError { impl UserError {
pub(crate) fn new(code: ErrorCode, msg: &str) -> Self { Self { code, msg: msg.to_owned() } } pub(crate) fn new(code: ErrorCode, msg: &str) -> Self { Self { code, msg: msg.to_owned() } }
pub(crate) fn code(code: ErrorCode) -> Self { Self { code, msg: "".to_owned() } }
pub fn context<T: Debug>(mut self, error: T) -> Self {
self.msg = format!("{:?}", error);
self
}
static_user_error!(email_empty, ErrorCode::EmailIsEmpty);
static_user_error!(email_format, ErrorCode::EmailFormatInvalid);
static_user_error!(email_exist, ErrorCode::EmailAlreadyExists);
static_user_error!(password_empty, ErrorCode::PasswordIsEmpty);
static_user_error!(passworkd_too_long, ErrorCode::PasswordTooLong);
static_user_error!(password_forbid_char, ErrorCode::PasswordContainsForbidCharacters);
static_user_error!(password_format, ErrorCode::PasswordFormatInvalid);
static_user_error!(password_not_match, ErrorCode::PasswordNotMatch);
static_user_error!(name_too_long, ErrorCode::UserNameTooLong);
static_user_error!(name_forbid_char, ErrorCode::UserNameContainForbiddenCharacters);
static_user_error!(name_empty, ErrorCode::UserNameIsEmpty);
static_user_error!(user_id, ErrorCode::UserIdInvalid);
static_user_error!(unauthorized, ErrorCode::UserUnauthorized);
static_user_error!(user_not_exist, ErrorCode::UserNotExist);
static_user_error!(internal, ErrorCode::InternalError);
} }
#[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)] #[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)]
pub enum ErrorCode { pub enum ErrorCode {
#[display(fmt = "Unknown")]
Unknown = 0,
#[display(fmt = "Database init failed")]
UserDatabaseInitFailed = 1,
#[display(fmt = "Acquire database write lock failed")]
AcquireWriteLockedFailed = 2,
#[display(fmt = "Acquire database read lock failed")]
AcquireReadLockedFailed = 3,
#[display(fmt = "Opening database is not belonging to the current user")]
UserDatabaseDidNotMatch = 4,
#[display(fmt = "Email can not be empty or whitespace")] #[display(fmt = "Email can not be empty or whitespace")]
EmailIsEmpty = 20, EmailIsEmpty = 0,
#[display(fmt = "Email format is not valid")] #[display(fmt = "Email format is not valid")]
EmailFormatInvalid = 21, EmailFormatInvalid = 1,
#[display(fmt = "Email already exists")] #[display(fmt = "Email already exists")]
EmailAlreadyExists = 22, EmailAlreadyExists = 2,
#[display(fmt = "Password can not be empty or whitespace")] #[display(fmt = "Password can not be empty or whitespace")]
PasswordIsEmpty = 30, PasswordIsEmpty = 10,
#[display(fmt = "Password format too long")] #[display(fmt = "Password format too long")]
PasswordTooLong = 31, PasswordTooLong = 11,
#[display(fmt = "Password contains forbidden characters.")] #[display(fmt = "Password contains forbidden characters.")]
PasswordContainsForbidCharacters = 32, PasswordContainsForbidCharacters = 12,
#[display(fmt = "Password should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric")] #[display(fmt = "Password should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric")]
PasswordFormatInvalid = 33, PasswordFormatInvalid = 13,
#[display(fmt = "Password not match")] #[display(fmt = "Password not match")]
PasswordNotMatch = 34, PasswordNotMatch = 14,
#[display(fmt = "User name is too long")] #[display(fmt = "User name is too long")]
UserNameTooLong = 40, UserNameTooLong = 20,
#[display(fmt = "User name contain forbidden characters")] #[display(fmt = "User name contain forbidden characters")]
ContainForbiddenCharacters = 41, UserNameContainForbiddenCharacters = 21,
#[display(fmt = "User name can not be empty or whitespace")] #[display(fmt = "User name can not be empty or whitespace")]
UserNameIsEmpty = 42, UserNameIsEmpty = 22,
#[display(fmt = "User workspace is invalid")]
UserWorkspaceInvalid = 50,
#[display(fmt = "User id is invalid")] #[display(fmt = "User id is invalid")]
UserIdInvalid = 51, UserIdInvalid = 23,
#[display(fmt = "User token is invalid")] #[display(fmt = "User token is invalid")]
UserUnauthorized = 54, UserUnauthorized = 24,
#[display(fmt = "User not exist")] #[display(fmt = "User not exist")]
UserNotExist = 55, UserNotExist = 25,
#[display(fmt = "Internal error")] #[display(fmt = "Internal error")]
InternalError = 100, InternalError = 100,
}
impl std::convert::Into<UserError> for ErrorCode {
fn into(self) -> UserError { UserError::new(self, "") }
} }
impl std::default::Default for ErrorCode { impl std::default::Default for ErrorCode {
fn default() -> Self { ErrorCode::Unknown } fn default() -> Self { ErrorCode::InternalError }
} }
impl std::convert::From<flowy_database::Error> for UserError { impl std::convert::From<flowy_database::Error> for UserError {
fn from(error: flowy_database::Error) -> Self { fn from(error: flowy_database::Error) -> Self {
match error { match error {
flowy_database::Error::NotFound => ErrorBuilder::new(ErrorCode::UserNotExist).error(error).build(), flowy_database::Error::NotFound => UserError::user_not_exist().context(error),
_ => ErrorBuilder::new(ErrorCode::InternalError).error(error).build(), _ => UserError::internal().context(error),
} }
} }
} }
impl std::convert::From<::r2d2::Error> for UserError { impl std::convert::From<::r2d2::Error> for UserError {
fn from(error: r2d2::Error) -> Self { ErrorBuilder::new(ErrorCode::InternalError).error(error).build() } fn from(error: r2d2::Error) -> Self { UserError::internal().context(error) }
} }
// use diesel::result::{Error, DatabaseErrorKind}; // use diesel::result::{Error, DatabaseErrorKind};
// use flowy_sqlite::ErrorKind; // use flowy_sqlite::ErrorKind;
impl std::convert::From<flowy_sqlite::Error> for UserError { impl std::convert::From<flowy_sqlite::Error> for UserError {
fn from(error: flowy_sqlite::Error) -> Self { ErrorBuilder::new(ErrorCode::InternalError).error(error).build() } fn from(error: flowy_sqlite::Error) -> Self { UserError::internal().context(error) }
} }
impl std::convert::From<flowy_net::errors::ServerError> for UserError { impl std::convert::From<flowy_net::errors::ServerError> for UserError {
fn from(error: flowy_net::errors::ServerError) -> Self { fn from(error: flowy_net::errors::ServerError) -> Self {
let code = server_error_to_user_error(error.code); let code = server_error_to_user_error(error.code);
ErrorBuilder::new(code).error(error.msg).build() UserError::new(code, &error.msg)
} }
} }
@ -113,12 +138,3 @@ impl flowy_dispatch::Error for UserError {
ResponseBuilder::Err().data(bytes).build() ResponseBuilder::Err().data(bytes).build()
} }
} }
pub type ErrorBuilder = flowy_infra::errors::Builder<ErrorCode, UserError>;
impl flowy_infra::errors::Build<ErrorCode> for UserError {
fn build(code: ErrorCode, msg: String) -> Self {
let msg = if msg.is_empty() { format!("{}", code) } else { msg };
UserError::new(code, &msg)
}
}

View File

@ -1,4 +1,2 @@
mod model; mod model;
pub use model::*; pub use model::*;

View File

@ -51,7 +51,7 @@ impl UserError {
self.code self.code
} }
pub fn clear_code(&mut self) { pub fn clear_code(&mut self) {
self.code = ErrorCode::Unknown; self.code = ErrorCode::EmailIsEmpty;
} }
// Param is passed by value, moved // Param is passed by value, moved
@ -113,7 +113,7 @@ impl ::protobuf::Message for UserError {
#[allow(unused_variables)] #[allow(unused_variables)]
fn compute_size(&self) -> u32 { fn compute_size(&self) -> u32 {
let mut my_size = 0; let mut my_size = 0;
if self.code != ErrorCode::Unknown { if self.code != ErrorCode::EmailIsEmpty {
my_size += ::protobuf::rt::enum_size(1, self.code); my_size += ::protobuf::rt::enum_size(1, self.code);
} }
if !self.msg.is_empty() { if !self.msg.is_empty() {
@ -125,7 +125,7 @@ impl ::protobuf::Message for UserError {
} }
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
if self.code != ErrorCode::Unknown { if self.code != ErrorCode::EmailIsEmpty {
os.write_enum(1, ::protobuf::ProtobufEnum::value(&self.code))?; os.write_enum(1, ::protobuf::ProtobufEnum::value(&self.code))?;
} }
if !self.msg.is_empty() { if !self.msg.is_empty() {
@ -195,7 +195,7 @@ impl ::protobuf::Message for UserError {
impl ::protobuf::Clear for UserError { impl ::protobuf::Clear for UserError {
fn clear(&mut self) { fn clear(&mut self) {
self.code = ErrorCode::Unknown; self.code = ErrorCode::EmailIsEmpty;
self.msg.clear(); self.msg.clear();
self.unknown_fields.clear(); self.unknown_fields.clear();
} }
@ -215,26 +215,20 @@ impl ::protobuf::reflect::ProtobufValue for UserError {
#[derive(Clone,PartialEq,Eq,Debug,Hash)] #[derive(Clone,PartialEq,Eq,Debug,Hash)]
pub enum ErrorCode { pub enum ErrorCode {
Unknown = 0, EmailIsEmpty = 0,
UserDatabaseInitFailed = 1, EmailFormatInvalid = 1,
AcquireWriteLockedFailed = 2, EmailAlreadyExists = 2,
AcquireReadLockedFailed = 3, PasswordIsEmpty = 10,
UserDatabaseDidNotMatch = 4, PasswordTooLong = 11,
EmailIsEmpty = 20, PasswordContainsForbidCharacters = 12,
EmailFormatInvalid = 21, PasswordFormatInvalid = 13,
EmailAlreadyExists = 22, PasswordNotMatch = 14,
PasswordIsEmpty = 30, UserNameTooLong = 20,
PasswordTooLong = 31, UserNameContainForbiddenCharacters = 21,
PasswordContainsForbidCharacters = 32, UserNameIsEmpty = 22,
PasswordFormatInvalid = 33, UserIdInvalid = 23,
PasswordNotMatch = 34, UserUnauthorized = 24,
UserNameTooLong = 40, UserNotExist = 25,
ContainForbiddenCharacters = 41,
UserNameIsEmpty = 42,
UserWorkspaceInvalid = 50,
UserIdInvalid = 51,
UserUnauthorized = 54,
UserNotExist = 55,
InternalError = 100, InternalError = 100,
} }
@ -245,26 +239,20 @@ impl ::protobuf::ProtobufEnum for ErrorCode {
fn from_i32(value: i32) -> ::std::option::Option<ErrorCode> { fn from_i32(value: i32) -> ::std::option::Option<ErrorCode> {
match value { match value {
0 => ::std::option::Option::Some(ErrorCode::Unknown), 0 => ::std::option::Option::Some(ErrorCode::EmailIsEmpty),
1 => ::std::option::Option::Some(ErrorCode::UserDatabaseInitFailed), 1 => ::std::option::Option::Some(ErrorCode::EmailFormatInvalid),
2 => ::std::option::Option::Some(ErrorCode::AcquireWriteLockedFailed), 2 => ::std::option::Option::Some(ErrorCode::EmailAlreadyExists),
3 => ::std::option::Option::Some(ErrorCode::AcquireReadLockedFailed), 10 => ::std::option::Option::Some(ErrorCode::PasswordIsEmpty),
4 => ::std::option::Option::Some(ErrorCode::UserDatabaseDidNotMatch), 11 => ::std::option::Option::Some(ErrorCode::PasswordTooLong),
20 => ::std::option::Option::Some(ErrorCode::EmailIsEmpty), 12 => ::std::option::Option::Some(ErrorCode::PasswordContainsForbidCharacters),
21 => ::std::option::Option::Some(ErrorCode::EmailFormatInvalid), 13 => ::std::option::Option::Some(ErrorCode::PasswordFormatInvalid),
22 => ::std::option::Option::Some(ErrorCode::EmailAlreadyExists), 14 => ::std::option::Option::Some(ErrorCode::PasswordNotMatch),
30 => ::std::option::Option::Some(ErrorCode::PasswordIsEmpty), 20 => ::std::option::Option::Some(ErrorCode::UserNameTooLong),
31 => ::std::option::Option::Some(ErrorCode::PasswordTooLong), 21 => ::std::option::Option::Some(ErrorCode::UserNameContainForbiddenCharacters),
32 => ::std::option::Option::Some(ErrorCode::PasswordContainsForbidCharacters), 22 => ::std::option::Option::Some(ErrorCode::UserNameIsEmpty),
33 => ::std::option::Option::Some(ErrorCode::PasswordFormatInvalid), 23 => ::std::option::Option::Some(ErrorCode::UserIdInvalid),
34 => ::std::option::Option::Some(ErrorCode::PasswordNotMatch), 24 => ::std::option::Option::Some(ErrorCode::UserUnauthorized),
40 => ::std::option::Option::Some(ErrorCode::UserNameTooLong), 25 => ::std::option::Option::Some(ErrorCode::UserNotExist),
41 => ::std::option::Option::Some(ErrorCode::ContainForbiddenCharacters),
42 => ::std::option::Option::Some(ErrorCode::UserNameIsEmpty),
50 => ::std::option::Option::Some(ErrorCode::UserWorkspaceInvalid),
51 => ::std::option::Option::Some(ErrorCode::UserIdInvalid),
54 => ::std::option::Option::Some(ErrorCode::UserUnauthorized),
55 => ::std::option::Option::Some(ErrorCode::UserNotExist),
100 => ::std::option::Option::Some(ErrorCode::InternalError), 100 => ::std::option::Option::Some(ErrorCode::InternalError),
_ => ::std::option::Option::None _ => ::std::option::Option::None
} }
@ -272,11 +260,6 @@ impl ::protobuf::ProtobufEnum for ErrorCode {
fn values() -> &'static [Self] { fn values() -> &'static [Self] {
static values: &'static [ErrorCode] = &[ static values: &'static [ErrorCode] = &[
ErrorCode::Unknown,
ErrorCode::UserDatabaseInitFailed,
ErrorCode::AcquireWriteLockedFailed,
ErrorCode::AcquireReadLockedFailed,
ErrorCode::UserDatabaseDidNotMatch,
ErrorCode::EmailIsEmpty, ErrorCode::EmailIsEmpty,
ErrorCode::EmailFormatInvalid, ErrorCode::EmailFormatInvalid,
ErrorCode::EmailAlreadyExists, ErrorCode::EmailAlreadyExists,
@ -286,9 +269,8 @@ impl ::protobuf::ProtobufEnum for ErrorCode {
ErrorCode::PasswordFormatInvalid, ErrorCode::PasswordFormatInvalid,
ErrorCode::PasswordNotMatch, ErrorCode::PasswordNotMatch,
ErrorCode::UserNameTooLong, ErrorCode::UserNameTooLong,
ErrorCode::ContainForbiddenCharacters, ErrorCode::UserNameContainForbiddenCharacters,
ErrorCode::UserNameIsEmpty, ErrorCode::UserNameIsEmpty,
ErrorCode::UserWorkspaceInvalid,
ErrorCode::UserIdInvalid, ErrorCode::UserIdInvalid,
ErrorCode::UserUnauthorized, ErrorCode::UserUnauthorized,
ErrorCode::UserNotExist, ErrorCode::UserNotExist,
@ -310,7 +292,7 @@ impl ::std::marker::Copy for ErrorCode {
impl ::std::default::Default for ErrorCode { impl ::std::default::Default for ErrorCode {
fn default() -> Self { fn default() -> Self {
ErrorCode::Unknown ErrorCode::EmailIsEmpty
} }
} }
@ -323,69 +305,54 @@ impl ::protobuf::reflect::ProtobufValue for ErrorCode {
static file_descriptor_proto_data: &'static [u8] = b"\ static file_descriptor_proto_data: &'static [u8] = b"\
\n\x0cerrors.proto\"=\n\tUserError\x12\x1e\n\x04code\x18\x01\x20\x01(\ \n\x0cerrors.proto\"=\n\tUserError\x12\x1e\n\x04code\x18\x01\x20\x01(\
\x0e2\n.ErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03msg*\ \x0e2\n.ErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03msg*\
\x81\x04\n\tErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x1a\n\x16UserDataba\ \xee\x02\n\tErrorCode\x12\x10\n\x0cEmailIsEmpty\x10\0\x12\x16\n\x12Email\
seInitFailed\x10\x01\x12\x1c\n\x18AcquireWriteLockedFailed\x10\x02\x12\ FormatInvalid\x10\x01\x12\x16\n\x12EmailAlreadyExists\x10\x02\x12\x13\n\
\x1b\n\x17AcquireReadLockedFailed\x10\x03\x12\x1b\n\x17UserDatabaseDidNo\ \x0fPasswordIsEmpty\x10\n\x12\x13\n\x0fPasswordTooLong\x10\x0b\x12$\n\
tMatch\x10\x04\x12\x10\n\x0cEmailIsEmpty\x10\x14\x12\x16\n\x12EmailForma\ \x20PasswordContainsForbidCharacters\x10\x0c\x12\x19\n\x15PasswordFormat\
tInvalid\x10\x15\x12\x16\n\x12EmailAlreadyExists\x10\x16\x12\x13\n\x0fPa\ Invalid\x10\r\x12\x14\n\x10PasswordNotMatch\x10\x0e\x12\x13\n\x0fUserNam\
sswordIsEmpty\x10\x1e\x12\x13\n\x0fPasswordTooLong\x10\x1f\x12$\n\x20Pas\ eTooLong\x10\x14\x12&\n\"UserNameContainForbiddenCharacters\x10\x15\x12\
swordContainsForbidCharacters\x10\x20\x12\x19\n\x15PasswordFormatInvalid\ \x13\n\x0fUserNameIsEmpty\x10\x16\x12\x11\n\rUserIdInvalid\x10\x17\x12\
\x10!\x12\x14\n\x10PasswordNotMatch\x10\"\x12\x13\n\x0fUserNameTooLong\ \x14\n\x10UserUnauthorized\x10\x18\x12\x10\n\x0cUserNotExist\x10\x19\x12\
\x10(\x12\x1e\n\x1aContainForbiddenCharacters\x10)\x12\x13\n\x0fUserName\ \x11\n\rInternalError\x10dJ\x97\x06\n\x06\x12\x04\0\0\x16\x01\n\x08\n\
IsEmpty\x10*\x12\x18\n\x14UserWorkspaceInvalid\x102\x12\x11\n\rUserIdInv\ \x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\
alid\x103\x12\x14\n\x10UserUnauthorized\x106\x12\x10\n\x0cUserNotExist\ \x04\0\x01\x12\x03\x02\x08\x11\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\
\x107\x12\x11\n\rInternalError\x10dJ\x8d\x08\n\x06\x12\x04\0\0\x1c\x01\n\ \x17\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x03\x04\r\n\x0c\n\x05\x04\0\x02\
\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\ \0\x01\x12\x03\x03\x0e\x12\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x15\
\n\x03\x04\0\x01\x12\x03\x02\x08\x11\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\ \x16\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\x02\
\x04\x17\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x03\x04\r\n\x0c\n\x05\x04\0\ \x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\
\x02\0\x01\x12\x03\x03\x0e\x12\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\ \x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\0\
\x15\x16\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\ \x12\x04\x06\0\x16\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x0e\n\x0b\n\
\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\ \x04\x05\0\x02\0\x12\x03\x07\x04\x15\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\
\x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\ \x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x13\x14\n\x0b\n\x04\
\0\x12\x04\x06\0\x1c\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x0e\n\x0b\n\ \x05\0\x02\x01\x12\x03\x08\x04\x1b\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\
\x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\ \x08\x04\x16\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\x19\x1a\n\x0b\n\
\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\ \x04\x05\0\x02\x02\x12\x03\t\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x01\x12\
\x05\0\x02\x01\x12\x03\x08\x04\x1f\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\ \x03\t\x04\x16\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x19\x1a\n\x0b\n\
\x08\x04\x1a\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\x1d\x1e\n\x0b\n\ \x04\x05\0\x02\x03\x12\x03\n\x04\x19\n\x0c\n\x05\x05\0\x02\x03\x01\x12\
\x04\x05\0\x02\x02\x12\x03\t\x04!\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\ \x03\n\x04\x13\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\n\x16\x18\n\x0b\n\
\t\x04\x1c\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x1f\x20\n\x0b\n\x04\ \x04\x05\0\x02\x04\x12\x03\x0b\x04\x19\n\x0c\n\x05\x05\0\x02\x04\x01\x12\
\x05\0\x02\x03\x12\x03\n\x04\x20\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\ \x03\x0b\x04\x13\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\x0b\x16\x18\n\x0b\
\x04\x1b\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\n\x1e\x1f\n\x0b\n\x04\x05\ \n\x04\x05\0\x02\x05\x12\x03\x0c\x04*\n\x0c\n\x05\x05\0\x02\x05\x01\x12\
\0\x02\x04\x12\x03\x0b\x04\x20\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\ \x03\x0c\x04$\n\x0c\n\x05\x05\0\x02\x05\x02\x12\x03\x0c')\n\x0b\n\x04\
\x04\x1b\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\x0b\x1e\x1f\n\x0b\n\x04\ \x05\0\x02\x06\x12\x03\r\x04\x1f\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\
\x05\0\x02\x05\x12\x03\x0c\x04\x16\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\ \x04\x19\n\x0c\n\x05\x05\0\x02\x06\x02\x12\x03\r\x1c\x1e\n\x0b\n\x04\x05\
\x0c\x04\x10\n\x0c\n\x05\x05\0\x02\x05\x02\x12\x03\x0c\x13\x15\n\x0b\n\ \0\x02\x07\x12\x03\x0e\x04\x1a\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\
\x04\x05\0\x02\x06\x12\x03\r\x04\x1c\n\x0c\n\x05\x05\0\x02\x06\x01\x12\ \x04\x14\n\x0c\n\x05\x05\0\x02\x07\x02\x12\x03\x0e\x17\x19\n\x0b\n\x04\
\x03\r\x04\x16\n\x0c\n\x05\x05\0\x02\x06\x02\x12\x03\r\x19\x1b\n\x0b\n\ \x05\0\x02\x08\x12\x03\x0f\x04\x19\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\
\x04\x05\0\x02\x07\x12\x03\x0e\x04\x1c\n\x0c\n\x05\x05\0\x02\x07\x01\x12\ \x0f\x04\x13\n\x0c\n\x05\x05\0\x02\x08\x02\x12\x03\x0f\x16\x18\n\x0b\n\
\x03\x0e\x04\x16\n\x0c\n\x05\x05\0\x02\x07\x02\x12\x03\x0e\x19\x1b\n\x0b\ \x04\x05\0\x02\t\x12\x03\x10\x04,\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\
\n\x04\x05\0\x02\x08\x12\x03\x0f\x04\x19\n\x0c\n\x05\x05\0\x02\x08\x01\ \x10\x04&\n\x0c\n\x05\x05\0\x02\t\x02\x12\x03\x10)+\n\x0b\n\x04\x05\0\
\x12\x03\x0f\x04\x13\n\x0c\n\x05\x05\0\x02\x08\x02\x12\x03\x0f\x16\x18\n\ \x02\n\x12\x03\x11\x04\x19\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\
\x0b\n\x04\x05\0\x02\t\x12\x03\x10\x04\x19\n\x0c\n\x05\x05\0\x02\t\x01\ \x13\n\x0c\n\x05\x05\0\x02\n\x02\x12\x03\x11\x16\x18\n\x0b\n\x04\x05\0\
\x12\x03\x10\x04\x13\n\x0c\n\x05\x05\0\x02\t\x02\x12\x03\x10\x16\x18\n\ \x02\x0b\x12\x03\x12\x04\x17\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\
\x0b\n\x04\x05\0\x02\n\x12\x03\x11\x04*\n\x0c\n\x05\x05\0\x02\n\x01\x12\ \x04\x11\n\x0c\n\x05\x05\0\x02\x0b\x02\x12\x03\x12\x14\x16\n\x0b\n\x04\
\x03\x11\x04$\n\x0c\n\x05\x05\0\x02\n\x02\x12\x03\x11')\n\x0b\n\x04\x05\
\0\x02\x0b\x12\x03\x12\x04\x1f\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\
\x04\x19\n\x0c\n\x05\x05\0\x02\x0b\x02\x12\x03\x12\x1c\x1e\n\x0b\n\x04\
\x05\0\x02\x0c\x12\x03\x13\x04\x1a\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\ \x05\0\x02\x0c\x12\x03\x13\x04\x1a\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\
\x13\x04\x14\n\x0c\n\x05\x05\0\x02\x0c\x02\x12\x03\x13\x17\x19\n\x0b\n\ \x13\x04\x14\n\x0c\n\x05\x05\0\x02\x0c\x02\x12\x03\x13\x17\x19\n\x0b\n\
\x04\x05\0\x02\r\x12\x03\x14\x04\x19\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\ \x04\x05\0\x02\r\x12\x03\x14\x04\x16\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\
\x14\x04\x13\n\x0c\n\x05\x05\0\x02\r\x02\x12\x03\x14\x16\x18\n\x0b\n\x04\ \x14\x04\x10\n\x0c\n\x05\x05\0\x02\r\x02\x12\x03\x14\x13\x15\n\x0b\n\x04\
\x05\0\x02\x0e\x12\x03\x15\x04$\n\x0c\n\x05\x05\0\x02\x0e\x01\x12\x03\ \x05\0\x02\x0e\x12\x03\x15\x04\x18\n\x0c\n\x05\x05\0\x02\x0e\x01\x12\x03\
\x15\x04\x1e\n\x0c\n\x05\x05\0\x02\x0e\x02\x12\x03\x15!#\n\x0b\n\x04\x05\ \x15\x04\x11\n\x0c\n\x05\x05\0\x02\x0e\x02\x12\x03\x15\x14\x17b\x06proto\
\0\x02\x0f\x12\x03\x16\x04\x19\n\x0c\n\x05\x05\0\x02\x0f\x01\x12\x03\x16\ 3\
\x04\x13\n\x0c\n\x05\x05\0\x02\x0f\x02\x12\x03\x16\x16\x18\n\x0b\n\x04\
\x05\0\x02\x10\x12\x03\x17\x04\x1e\n\x0c\n\x05\x05\0\x02\x10\x01\x12\x03\
\x17\x04\x18\n\x0c\n\x05\x05\0\x02\x10\x02\x12\x03\x17\x1b\x1d\n\x0b\n\
\x04\x05\0\x02\x11\x12\x03\x18\x04\x17\n\x0c\n\x05\x05\0\x02\x11\x01\x12\
\x03\x18\x04\x11\n\x0c\n\x05\x05\0\x02\x11\x02\x12\x03\x18\x14\x16\n\x0b\
\n\x04\x05\0\x02\x12\x12\x03\x19\x04\x1a\n\x0c\n\x05\x05\0\x02\x12\x01\
\x12\x03\x19\x04\x14\n\x0c\n\x05\x05\0\x02\x12\x02\x12\x03\x19\x17\x19\n\
\x0b\n\x04\x05\0\x02\x13\x12\x03\x1a\x04\x16\n\x0c\n\x05\x05\0\x02\x13\
\x01\x12\x03\x1a\x04\x10\n\x0c\n\x05\x05\0\x02\x13\x02\x12\x03\x1a\x13\
\x15\n\x0b\n\x04\x05\0\x02\x14\x12\x03\x1b\x04\x18\n\x0c\n\x05\x05\0\x02\
\x14\x01\x12\x03\x1b\x04\x11\n\x0c\n\x05\x05\0\x02\x14\x02\x12\x03\x1b\
\x14\x17b\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;

View File

@ -1,19 +1,19 @@
// Auto-generated, do not edit // Auto-generated, do not edit
mod observable; mod observable;
pub use observable::*; pub use observable::*;
mod user_table; mod user_table;
pub use user_table::*; pub use user_table::*;
mod errors; mod errors;
pub use errors::*; pub use errors::*;
mod user_profile; mod user_profile;
pub use user_profile::*; pub use user_profile::*;
mod event; mod event;
pub use event::*; pub use event::*;
mod auth; mod auth;
pub use auth::*; pub use auth::*;

View File

@ -5,25 +5,19 @@ message UserError {
string msg = 2; string msg = 2;
} }
enum ErrorCode { enum ErrorCode {
Unknown = 0; EmailIsEmpty = 0;
UserDatabaseInitFailed = 1; EmailFormatInvalid = 1;
AcquireWriteLockedFailed = 2; EmailAlreadyExists = 2;
AcquireReadLockedFailed = 3; PasswordIsEmpty = 10;
UserDatabaseDidNotMatch = 4; PasswordTooLong = 11;
EmailIsEmpty = 20; PasswordContainsForbidCharacters = 12;
EmailFormatInvalid = 21; PasswordFormatInvalid = 13;
EmailAlreadyExists = 22; PasswordNotMatch = 14;
PasswordIsEmpty = 30; UserNameTooLong = 20;
PasswordTooLong = 31; UserNameContainForbiddenCharacters = 21;
PasswordContainsForbidCharacters = 32; UserNameIsEmpty = 22;
PasswordFormatInvalid = 33; UserIdInvalid = 23;
PasswordNotMatch = 34; UserUnauthorized = 24;
UserNameTooLong = 40; UserNotExist = 25;
ContainForbiddenCharacters = 41;
UserNameIsEmpty = 42;
UserWorkspaceInvalid = 50;
UserIdInvalid = 51;
UserUnauthorized = 54;
UserNotExist = 55;
InternalError = 100; InternalError = 100;
} }

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
entities::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserParams, UserProfile}, entities::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserParams, UserProfile},
errors::{ErrorBuilder, ErrorCode, UserError}, errors::UserError,
}; };
use crate::services::server::UserServerAPI; use crate::services::server::UserServerAPI;
@ -40,6 +40,6 @@ impl UserServerAPI for UserServerMock {
fn update_user(&self, _token: &str, _params: UpdateUserParams) -> ResultFuture<(), UserError> { ResultFuture::new(async { Ok(()) }) } fn update_user(&self, _token: &str, _params: UpdateUserParams) -> ResultFuture<(), UserError> { ResultFuture::new(async { Ok(()) }) }
fn get_user(&self, _token: &str) -> ResultFuture<UserProfile, UserError> { fn get_user(&self, _token: &str) -> ResultFuture<UserProfile, UserError> {
ResultFuture::new(async { Err(ErrorBuilder::new(ErrorCode::Unknown).msg("mock data, ignore this error").build()) }) ResultFuture::new(async { Err(UserError::internal().context("mock data, ignore this error")) })
} }
} }

View File

@ -1,4 +1,4 @@
use crate::errors::{ErrorBuilder, ErrorCode, UserError}; use crate::errors::UserError;
use flowy_database::{DBConnection, Database}; use flowy_database::{DBConnection, Database};
use flowy_sqlite::ConnectionPool; use flowy_sqlite::ConnectionPool;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -18,20 +18,18 @@ impl UserDB {
fn open_user_db(&self, user_id: &str) -> Result<(), UserError> { fn open_user_db(&self, user_id: &str) -> Result<(), UserError> {
if user_id.is_empty() { if user_id.is_empty() {
return Err(ErrorBuilder::new(ErrorCode::UserDatabaseInitFailed).msg("user id is empty").build()); return Err(UserError::internal().context("user id is empty"));
} }
log::info!("open user db {}", user_id); log::info!("open user db {}", user_id);
let dir = format!("{}/{}", self.db_dir, user_id); let dir = format!("{}/{}", self.db_dir, user_id);
let db = flowy_database::init(&dir).map_err(|e| { let db = flowy_database::init(&dir).map_err(|e| {
log::error!("init user db failed, {:?}, user_id: {}", e, user_id); log::error!("init user db failed, {:?}, user_id: {}", e, user_id);
ErrorBuilder::new(ErrorCode::UserDatabaseInitFailed).error(e).build() UserError::internal().context(e)
})?; })?;
match DB_MAP.try_write_for(Duration::from_millis(300)) { match DB_MAP.try_write_for(Duration::from_millis(300)) {
None => Err(ErrorBuilder::new(ErrorCode::AcquireWriteLockedFailed) None => Err(UserError::internal().context(format!("Acquire write lock to save user db failed"))),
.msg(format!("Open user db failed"))
.build()),
Some(mut write_guard) => { Some(mut write_guard) => {
write_guard.insert(user_id.to_owned(), db); write_guard.insert(user_id.to_owned(), db);
Ok(()) Ok(())
@ -41,9 +39,7 @@ impl UserDB {
pub(crate) fn close_user_db(&self, user_id: &str) -> Result<(), UserError> { pub(crate) fn close_user_db(&self, user_id: &str) -> Result<(), UserError> {
match DB_MAP.try_write_for(Duration::from_millis(300)) { match DB_MAP.try_write_for(Duration::from_millis(300)) {
None => Err(ErrorBuilder::new(ErrorCode::AcquireWriteLockedFailed) None => Err(UserError::internal().context(format!("Acquire write lock to close user db failed"))),
.msg(format!("Close user db failed"))
.build()),
Some(mut write_guard) => { Some(mut write_guard) => {
set_user_db_init(false, user_id); set_user_db_init(false, user_id);
write_guard.remove(user_id); write_guard.remove(user_id);
@ -71,13 +67,9 @@ impl UserDB {
} }
match DB_MAP.try_read_for(Duration::from_millis(300)) { match DB_MAP.try_read_for(Duration::from_millis(300)) {
None => Err(ErrorBuilder::new(ErrorCode::AcquireReadLockedFailed) None => Err(UserError::internal().context(format!("Acquire read lock to read user db failed"))),
.msg(format!("Read user db failed"))
.build()),
Some(read_guard) => match read_guard.get(user_id) { Some(read_guard) => match read_guard.get(user_id) {
None => Err(ErrorBuilder::new(ErrorCode::UserDatabaseInitFailed) None => Err(UserError::internal().context("Get connection failed. The database is not initialization")),
.msg("Get connection failed. The database is not initialization")
.build()),
Some(database) => Ok(database.get_pool()), Some(database) => Ok(database.get_pool()),
}, },
} }

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
entities::{SignInParams, SignUpParams, UpdateUserParams, UserProfile}, entities::{SignInParams, SignUpParams, UpdateUserParams, UserProfile},
errors::{ErrorBuilder, ErrorCode, UserError}, errors::{ErrorCode, UserError},
services::user::database::UserDB, services::user::database::UserDB,
sql_tables::{UserTable, UserTableChangeset}, sql_tables::{UserTable, UserTableChangeset},
}; };
@ -214,7 +214,7 @@ impl UserSession {
} }
match session { match session {
None => Err(ErrorBuilder::new(ErrorCode::UserUnauthorized).build()), None => Err(UserError::unauthorized()),
Some(session) => Ok(session), Some(session) => Ok(session),
} }
} }

View File

@ -51,12 +51,11 @@ impl TryInto<CreateAppParams> for CreateAppRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<CreateAppParams, Self::Error> { fn try_into(self) -> Result<CreateAppParams, Self::Error> {
let name = AppName::parse(self.name).map_err(|e| ErrorBuilder::new(ErrorCode::AppNameInvalid).msg(e).build())?; let name = AppName::parse(self.name).map_err(|e| WorkspaceError::app_name().context(e))?;
let id = WorkspaceId::parse(self.workspace_id).map_err(|e| ErrorBuilder::new(ErrorCode::WorkspaceIdInvalid).msg(e).build())?; let id = WorkspaceId::parse(self.workspace_id).map_err(|e| WorkspaceError::workspace_id().context(e))?;
let color_style = let color_style = AppColorStyle::parse(self.color_style).map_err(|e| WorkspaceError::color_style().context(e))?;
AppColorStyle::parse(self.color_style).map_err(|e| ErrorBuilder::new(ErrorCode::AppColorStyleInvalid).msg(e).build())?;
Ok(CreateAppParams { Ok(CreateAppParams {
workspace_id: id.0, workspace_id: id.0,

View File

@ -1,7 +1,4 @@
use crate::{ use crate::{entities::app::parser::AppId, errors::WorkspaceError};
entities::app::parser::AppId,
errors::{ErrorBuilder, ErrorCode, WorkspaceError},
};
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use std::convert::TryInto; use std::convert::TryInto;
@ -21,9 +18,7 @@ impl TryInto<DeleteAppParams> for DeleteAppRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<DeleteAppParams, Self::Error> { fn try_into(self) -> Result<DeleteAppParams, Self::Error> {
let app_id = AppId::parse(self.app_id) let app_id = AppId::parse(self.app_id).map_err(|e| WorkspaceError::app_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::AppIdInvalid).msg(e).build())?
.0;
Ok(DeleteAppParams { app_id }) Ok(DeleteAppParams { app_id })
} }

View File

@ -69,9 +69,7 @@ impl TryInto<QueryAppParams> for QueryAppRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<QueryAppParams, Self::Error> { fn try_into(self) -> Result<QueryAppParams, Self::Error> {
let app_id = AppId::parse(self.app_id) let app_id = AppId::parse(self.app_id).map_err(|e| WorkspaceError::app_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::AppIdInvalid).msg(e).build())?
.0;
Ok(QueryAppParams { Ok(QueryAppParams {
app_id, app_id,

View File

@ -3,7 +3,7 @@ use crate::{
parser::{AppColorStyle, AppId, AppName}, parser::{AppColorStyle, AppId, AppName},
ColorStyle, ColorStyle,
}, },
errors::{ErrorBuilder, ErrorCode, WorkspaceError}, errors::WorkspaceError,
}; };
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use std::convert::TryInto; use std::convert::TryInto;
@ -72,24 +72,18 @@ impl TryInto<UpdateAppParams> for UpdateAppRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<UpdateAppParams, Self::Error> { fn try_into(self) -> Result<UpdateAppParams, Self::Error> {
let app_id = AppId::parse(self.app_id) let app_id = AppId::parse(self.app_id).map_err(|e| WorkspaceError::app_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::AppIdInvalid).msg(e).build())?
.0;
let name = match self.name { let name = match self.name {
None => None, None => None,
Some(name) => Some( Some(name) => Some(AppName::parse(name).map_err(|e| WorkspaceError::workspace_name().context(e))?.0),
AppName::parse(name)
.map_err(|e| ErrorBuilder::new(ErrorCode::WorkspaceNameInvalid).msg(e).build())?
.0,
),
}; };
let color_style = match self.color_style { let color_style = match self.color_style {
None => None, None => None,
Some(color_style) => Some( Some(color_style) => Some(
AppColorStyle::parse(color_style) AppColorStyle::parse(color_style)
.map_err(|e| ErrorBuilder::new(ErrorCode::AppColorStyleInvalid).msg(e).build())? .map_err(|e| WorkspaceError::color_style().context(e))?
.0, .0,
), ),
}; };

View File

@ -1,5 +1,3 @@
use flowy_ot::core::Delta;
#[derive(Debug)] #[derive(Debug)]
pub struct DeltaData(pub Vec<u8>); pub struct DeltaData(pub Vec<u8>);

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
entities::{app::parser::AppId, view::parser::*}, entities::{app::parser::AppId, view::parser::*},
errors::{ErrorBuilder, ErrorCode, WorkspaceError}, errors::WorkspaceError,
impl_def_and_def_mut, impl_def_and_def_mut,
}; };
use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
@ -88,19 +88,15 @@ impl TryInto<CreateViewParams> for CreateViewRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<CreateViewParams, Self::Error> { fn try_into(self) -> Result<CreateViewParams, Self::Error> {
let name = ViewName::parse(self.name) let name = ViewName::parse(self.name).map_err(|e| WorkspaceError::view_name().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewNameInvalid).msg(e).build())?
.0;
let belong_to_id = AppId::parse(self.belong_to_id) let belong_to_id = AppId::parse(self.belong_to_id).map_err(|e| WorkspaceError::app_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::AppIdInvalid).msg(e).build())?
.0;
let thumbnail = match self.thumbnail { let thumbnail = match self.thumbnail {
None => "".to_string(), None => "".to_string(),
Some(thumbnail) => { Some(thumbnail) => {
ViewThumbnail::parse(thumbnail) ViewThumbnail::parse(thumbnail)
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewThumbnailInvalid).msg(e).build())? .map_err(|e| WorkspaceError::view_thumbnail().context(e))?
.0 .0
}, },
}; };

View File

@ -1,7 +1,4 @@
use crate::{ use crate::{entities::view::parser::ViewId, errors::WorkspaceError};
entities::view::parser::ViewId,
errors::{ErrorBuilder, ErrorCode, WorkspaceError},
};
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use flowy_document::entities::doc::QueryDocParams; use flowy_document::entities::doc::QueryDocParams;
use std::convert::TryInto; use std::convert::TryInto;
@ -22,9 +19,7 @@ impl TryInto<DeleteViewParams> for DeleteViewRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<DeleteViewParams, Self::Error> { fn try_into(self) -> Result<DeleteViewParams, Self::Error> {
let view_id = ViewId::parse(self.view_id) let view_id = ViewId::parse(self.view_id).map_err(|e| WorkspaceError::view_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewIdInvalid).msg(e).build())?
.0;
Ok(DeleteViewParams { view_id }) Ok(DeleteViewParams { view_id })
} }

View File

@ -1,7 +1,4 @@
use crate::{ use crate::{entities::view::parser::ViewId, errors::WorkspaceError};
entities::view::parser::ViewId,
errors::{ErrorBuilder, ErrorCode, WorkspaceError},
};
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use flowy_document::entities::doc::QueryDocParams; use flowy_document::entities::doc::QueryDocParams;
use std::convert::TryInto; use std::convert::TryInto;
@ -71,9 +68,7 @@ impl std::convert::Into<QueryDocParams> for QueryViewParams {
impl TryInto<QueryViewParams> for QueryViewRequest { impl TryInto<QueryViewParams> for QueryViewRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<QueryViewParams, Self::Error> { fn try_into(self) -> Result<QueryViewParams, Self::Error> {
let view_id = ViewId::parse(self.view_id) let view_id = ViewId::parse(self.view_id).map_err(|e| WorkspaceError::view_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewIdInvalid).msg(e).build())?
.0;
Ok(QueryViewParams { Ok(QueryViewParams {
view_id, view_id,
@ -93,9 +88,7 @@ impl std::convert::TryInto<QueryDocParams> for OpenViewRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<QueryDocParams, Self::Error> { fn try_into(self) -> Result<QueryDocParams, Self::Error> {
let view_id = ViewId::parse(self.view_id) let view_id = ViewId::parse(self.view_id).map_err(|e| WorkspaceError::view_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewIdInvalid).msg(e).build())?
.0;
Ok(QueryDocParams { doc_id: view_id }) Ok(QueryDocParams { doc_id: view_id })
} }
} }

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
entities::view::parser::{ViewId, *}, entities::view::parser::{ViewId, *},
errors::{ErrorBuilder, ErrorCode, WorkspaceError}, errors::WorkspaceError,
}; };
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use flowy_document::entities::doc::{ApplyChangesetParams, SaveDocParams}; use flowy_document::entities::doc::{ApplyChangesetParams, SaveDocParams};
@ -69,33 +69,23 @@ impl TryInto<UpdateViewParams> for UpdateViewRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<UpdateViewParams, Self::Error> { fn try_into(self) -> Result<UpdateViewParams, Self::Error> {
let view_id = ViewId::parse(self.view_id) let view_id = ViewId::parse(self.view_id).map_err(|e| WorkspaceError::view_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewIdInvalid).msg(e).build())?
.0;
let name = match self.name { let name = match self.name {
None => None, None => None,
Some(name) => Some( Some(name) => Some(ViewName::parse(name).map_err(|e| WorkspaceError::view_name().context(e))?.0),
ViewName::parse(name)
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewNameInvalid).msg(e).build())?
.0,
),
}; };
let desc = match self.desc { let desc = match self.desc {
None => None, None => None,
Some(desc) => Some( Some(desc) => Some(ViewDesc::parse(desc).map_err(|e| WorkspaceError::view_desc().context(e))?.0),
ViewDesc::parse(desc)
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewDescInvalid).msg(e).build())?
.0,
),
}; };
let thumbnail = match self.thumbnail { let thumbnail = match self.thumbnail {
None => None, None => None,
Some(thumbnail) => Some( Some(thumbnail) => Some(
ViewThumbnail::parse(thumbnail) ViewThumbnail::parse(thumbnail)
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewThumbnailInvalid).msg(e).build())? .map_err(|e| WorkspaceError::view_thumbnail().context(e))?
.0, .0,
), ),
}; };
@ -123,14 +113,10 @@ impl TryInto<SaveDocParams> for SaveViewDataRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<SaveDocParams, Self::Error> { fn try_into(self) -> Result<SaveDocParams, Self::Error> {
let view_id = ViewId::parse(self.view_id) let view_id = ViewId::parse(self.view_id).map_err(|e| WorkspaceError::view_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewIdInvalid).msg(e).build())?
.0;
// Opti: Vec<u8> -> Delta -> Vec<u8> // Opti: Vec<u8> -> Delta -> Vec<u8>
let data = DeltaData::parse(self.data) let data = DeltaData::parse(self.data).map_err(|e| WorkspaceError::view_data().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewDataInvalid).msg(e).build())?
.0;
Ok(SaveDocParams { id: view_id, data }) Ok(SaveDocParams { id: view_id, data })
} }
@ -149,14 +135,10 @@ impl TryInto<ApplyChangesetParams> for ApplyChangesetRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<ApplyChangesetParams, Self::Error> { fn try_into(self) -> Result<ApplyChangesetParams, Self::Error> {
let view_id = ViewId::parse(self.view_id) let view_id = ViewId::parse(self.view_id).map_err(|e| WorkspaceError::view_id().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewIdInvalid).msg(e).build())?
.0;
// Opti: Vec<u8> -> Delta -> Vec<u8> // Opti: Vec<u8> -> Delta -> Vec<u8>
let data = DeltaData::parse(self.data) let data = DeltaData::parse(self.data).map_err(|e| WorkspaceError::view_data().context(e))?.0;
.map_err(|e| ErrorBuilder::new(ErrorCode::ViewDataInvalid).msg(e).build())?
.0;
Ok(ApplyChangesetParams { id: view_id, data }) Ok(ApplyChangesetParams { id: view_id, data })
} }

View File

@ -28,8 +28,8 @@ impl TryInto<CreateWorkspaceParams> for CreateWorkspaceRequest {
type Error = WorkspaceError; type Error = WorkspaceError;
fn try_into(self) -> Result<CreateWorkspaceParams, Self::Error> { fn try_into(self) -> Result<CreateWorkspaceParams, Self::Error> {
let name = WorkspaceName::parse(self.name).map_err(|e| ErrorBuilder::new(ErrorCode::WorkspaceNameInvalid).msg(e).build())?; let name = WorkspaceName::parse(self.name).map_err(|e| WorkspaceError::workspace_name().context(e))?;
let desc = WorkspaceDesc::parse(self.desc).map_err(|e| ErrorBuilder::new(ErrorCode::WorkspaceDescInvalid).msg(e).build())?; let desc = WorkspaceDesc::parse(self.desc).map_err(|e| WorkspaceError::workspace_desc().context(e))?;
Ok(CreateWorkspaceParams { Ok(CreateWorkspaceParams {
name: name.0, name: name.0,

View File

@ -1,7 +1,4 @@
use crate::{ use crate::{entities::workspace::parser::WorkspaceId, errors::WorkspaceError};
entities::workspace::parser::WorkspaceId,
errors::{ErrorBuilder, ErrorCode, WorkspaceError},
};
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use std::convert::TryInto; use std::convert::TryInto;
@ -22,7 +19,7 @@ impl TryInto<DeleteWorkspaceParams> for DeleteWorkspaceRequest {
fn try_into(self) -> Result<DeleteWorkspaceParams, Self::Error> { fn try_into(self) -> Result<DeleteWorkspaceParams, Self::Error> {
let workspace_id = WorkspaceId::parse(self.workspace_id) let workspace_id = WorkspaceId::parse(self.workspace_id)
.map_err(|e| ErrorBuilder::new(ErrorCode::WorkspaceIdInvalid).msg(e).build())? .map_err(|e| WorkspaceError::workspace_id().context(e))?
.0; .0;
Ok(DeleteWorkspaceParams { workspace_id }) Ok(DeleteWorkspaceParams { workspace_id })

View File

@ -47,7 +47,7 @@ impl TryInto<QueryWorkspaceParams> for QueryWorkspaceRequest {
None => None, None => None,
Some(workspace_id) => Some( Some(workspace_id) => Some(
WorkspaceId::parse(workspace_id) WorkspaceId::parse(workspace_id)
.map_err(|e| ErrorBuilder::new(ErrorCode::WorkspaceIdInvalid).msg(e).build())? .map_err(|e| WorkspaceError::workspace_id().context(e))?
.0, .0,
), ),
}; };

View File

@ -36,12 +36,12 @@ impl TryInto<UpdateWorkspaceParams> for UpdateWorkspaceRequest {
None => None, None => None,
Some(name) => Some( Some(name) => Some(
WorkspaceName::parse(name) WorkspaceName::parse(name)
.map_err(|e| ErrorBuilder::new(ErrorCode::WorkspaceNameInvalid).msg(e).build())? .map_err(|e| WorkspaceError::workspace_name().context(e))?
.0, .0,
), ),
}; };
let id = WorkspaceId::parse(self.id).map_err(|e| ErrorBuilder::new(ErrorCode::WorkspaceIdInvalid).msg(e).build())?; let id = WorkspaceId::parse(self.id).map_err(|e| WorkspaceError::workspace_id().context(e))?;
Ok(UpdateWorkspaceParams { Ok(UpdateWorkspaceParams {
id: id.0, id: id.0,

View File

@ -4,7 +4,7 @@ use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_dispatch::prelude::{EventResponse, ResponseBuilder}; use flowy_dispatch::prelude::{EventResponse, ResponseBuilder};
use flowy_document::errors::DocError; use flowy_document::errors::DocError;
use flowy_net::errors::ErrorCode as ServerErrorCode; use flowy_net::errors::ErrorCode as ServerErrorCode;
use std::{convert::TryInto, fmt}; use std::{convert::TryInto, fmt, fmt::Debug};
#[derive(Debug, Default, Clone, ProtoBuf)] #[derive(Debug, Default, Clone, ProtoBuf)]
pub struct WorkspaceError { pub struct WorkspaceError {
@ -15,29 +15,55 @@ pub struct WorkspaceError {
pub msg: String, pub msg: String,
} }
macro_rules! static_workspace_error {
($name:ident, $status:expr) => {
#[allow(non_snake_case, missing_docs)]
pub fn $name() -> WorkspaceError {
WorkspaceError {
code: $status,
msg: format!("{}", $status),
}
}
};
}
impl WorkspaceError { impl WorkspaceError {
pub fn new(code: ErrorCode, msg: &str) -> Self { Self { code, msg: msg.to_owned() } } pub fn new(code: ErrorCode, msg: &str) -> Self { Self { code, msg: msg.to_owned() } }
static_workspace_error!(workspace_name, ErrorCode::WorkspaceNameInvalid);
static_workspace_error!(workspace_id, ErrorCode::WorkspaceIdInvalid);
static_workspace_error!(color_style, ErrorCode::AppColorStyleInvalid);
static_workspace_error!(workspace_desc, ErrorCode::WorkspaceDescInvalid);
static_workspace_error!(app_name, ErrorCode::AppNameInvalid);
static_workspace_error!(app_id, ErrorCode::AppIdInvalid);
static_workspace_error!(view_name, ErrorCode::ViewNameInvalid);
static_workspace_error!(view_thumbnail, ErrorCode::ViewThumbnailInvalid);
static_workspace_error!(view_id, ErrorCode::ViewIdInvalid);
static_workspace_error!(view_desc, ErrorCode::ViewDescInvalid);
static_workspace_error!(view_data, ErrorCode::ViewDataInvalid);
static_workspace_error!(unauthorized, ErrorCode::UserUnauthorized);
static_workspace_error!(internal, ErrorCode::InternalError);
static_workspace_error!(not_found, ErrorCode::RecordNotFound);
pub fn context<T: Debug>(mut self, error: T) -> Self {
self.msg = format!("{:?}", error);
self
}
} }
#[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)] #[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)]
pub enum ErrorCode { pub enum ErrorCode {
#[display(fmt = "Unknown")]
Unknown = 0,
#[display(fmt = "Workspace name is invalid")] #[display(fmt = "Workspace name is invalid")]
WorkspaceNameInvalid = 1, WorkspaceNameInvalid = 0,
#[display(fmt = "Workspace id is invalid")] #[display(fmt = "Workspace id is invalid")]
WorkspaceIdInvalid = 2, WorkspaceIdInvalid = 1,
#[display(fmt = "Color style of the App is invalid")] #[display(fmt = "Color style of the App is invalid")]
AppColorStyleInvalid = 3, AppColorStyleInvalid = 2,
#[display(fmt = "Workspace desc is invalid")] #[display(fmt = "Workspace desc is invalid")]
WorkspaceDescInvalid = 4, WorkspaceDescInvalid = 3,
#[display(fmt = "Current workspace not found")]
CurrentWorkspaceNotFound = 5,
#[display(fmt = "Id of the App is invalid")] #[display(fmt = "Id of the App is invalid")]
AppIdInvalid = 10, AppIdInvalid = 10,
@ -60,11 +86,8 @@ pub enum ErrorCode {
#[display(fmt = "View data is invalid")] #[display(fmt = "View data is invalid")]
ViewDataInvalid = 24, ViewDataInvalid = 24,
#[display(fmt = "UserIn is empty")]
UserIdIsEmpty = 100,
#[display(fmt = "User unauthorized")] #[display(fmt = "User unauthorized")]
UserUnauthorized = 101, UserUnauthorized = 100,
#[display(fmt = "Server error")] #[display(fmt = "Server error")]
InternalError = 1000, InternalError = 1000,
@ -73,22 +96,22 @@ pub enum ErrorCode {
} }
impl std::default::Default for ErrorCode { impl std::default::Default for ErrorCode {
fn default() -> Self { ErrorCode::Unknown } fn default() -> Self { ErrorCode::InternalError }
} }
impl std::convert::From<flowy_document::errors::DocError> for WorkspaceError { impl std::convert::From<flowy_document::errors::DocError> for WorkspaceError {
fn from(error: DocError) -> Self { ErrorBuilder::new(ErrorCode::InternalError).error(error).build() } fn from(error: DocError) -> Self { WorkspaceError::internal().context(error) }
} }
impl std::convert::From<flowy_net::errors::ServerError> for WorkspaceError { impl std::convert::From<flowy_net::errors::ServerError> for WorkspaceError {
fn from(error: flowy_net::errors::ServerError) -> Self { fn from(error: flowy_net::errors::ServerError) -> Self {
let code = server_error_to_workspace_error(error.code); let code = server_error_to_workspace_error(error.code);
ErrorBuilder::new(code).error(error.msg).build() WorkspaceError::new(code, &error.msg)
} }
} }
impl std::convert::From<flowy_database::Error> for WorkspaceError { impl std::convert::From<flowy_database::Error> for WorkspaceError {
fn from(error: flowy_database::Error) -> Self { ErrorBuilder::new(ErrorCode::InternalError).error(error).build() } fn from(error: flowy_database::Error) -> Self { WorkspaceError::internal().context(error) }
} }
impl flowy_dispatch::Error for WorkspaceError { impl flowy_dispatch::Error for WorkspaceError {
@ -102,15 +125,6 @@ impl fmt::Display for WorkspaceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}: {}", &self.code, &self.msg) } fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}: {}", &self.code, &self.msg) }
} }
pub type ErrorBuilder = flowy_infra::errors::Builder<ErrorCode, WorkspaceError>;
impl flowy_infra::errors::Build<ErrorCode> for WorkspaceError {
fn build(code: ErrorCode, msg: String) -> Self {
let msg = if msg.is_empty() { format!("{}", code) } else { msg };
WorkspaceError::new(code, &msg)
}
}
fn server_error_to_workspace_error(code: ServerErrorCode) -> ErrorCode { fn server_error_to_workspace_error(code: ServerErrorCode) -> ErrorCode {
match code { match code {
ServerErrorCode::UserUnauthorized => ErrorCode::UserUnauthorized, ServerErrorCode::UserUnauthorized => ErrorCode::UserUnauthorized,

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
errors::{ErrorBuilder, ErrorCode, WorkspaceError}, errors::WorkspaceError,
event::WorkspaceEvent, event::WorkspaceEvent,
handlers::*, handlers::*,
services::{server::construct_workspace_server, AppController, ViewController, WorkspaceController}, services::{server::construct_workspace_server, AppController, ViewController, WorkspaceController},
@ -22,9 +22,7 @@ pub trait WorkspaceDatabase: Send + Sync {
fn db_connection(&self) -> Result<DBConnection, WorkspaceError> { fn db_connection(&self) -> Result<DBConnection, WorkspaceError> {
let pool = self.db_pool()?; let pool = self.db_pool()?;
let conn = pool let conn = pool.get().map_err(|e| WorkspaceError::internal().context(e))?;
.get()
.map_err(|e| ErrorBuilder::new(ErrorCode::InternalError).error(e).build())?;
Ok(conn) Ok(conn)
} }
} }

View File

@ -1,4 +1,2 @@
mod model; mod model;
pub use model::*; pub use model::*;

View File

@ -51,7 +51,7 @@ impl WorkspaceError {
self.code self.code
} }
pub fn clear_code(&mut self) { pub fn clear_code(&mut self) {
self.code = ErrorCode::Unknown; self.code = ErrorCode::WorkspaceNameInvalid;
} }
// Param is passed by value, moved // Param is passed by value, moved
@ -113,7 +113,7 @@ impl ::protobuf::Message for WorkspaceError {
#[allow(unused_variables)] #[allow(unused_variables)]
fn compute_size(&self) -> u32 { fn compute_size(&self) -> u32 {
let mut my_size = 0; let mut my_size = 0;
if self.code != ErrorCode::Unknown { if self.code != ErrorCode::WorkspaceNameInvalid {
my_size += ::protobuf::rt::enum_size(1, self.code); my_size += ::protobuf::rt::enum_size(1, self.code);
} }
if !self.msg.is_empty() { if !self.msg.is_empty() {
@ -125,7 +125,7 @@ impl ::protobuf::Message for WorkspaceError {
} }
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
if self.code != ErrorCode::Unknown { if self.code != ErrorCode::WorkspaceNameInvalid {
os.write_enum(1, ::protobuf::ProtobufEnum::value(&self.code))?; os.write_enum(1, ::protobuf::ProtobufEnum::value(&self.code))?;
} }
if !self.msg.is_empty() { if !self.msg.is_empty() {
@ -195,7 +195,7 @@ impl ::protobuf::Message for WorkspaceError {
impl ::protobuf::Clear for WorkspaceError { impl ::protobuf::Clear for WorkspaceError {
fn clear(&mut self) { fn clear(&mut self) {
self.code = ErrorCode::Unknown; self.code = ErrorCode::WorkspaceNameInvalid;
self.msg.clear(); self.msg.clear();
self.unknown_fields.clear(); self.unknown_fields.clear();
} }
@ -215,12 +215,10 @@ impl ::protobuf::reflect::ProtobufValue for WorkspaceError {
#[derive(Clone,PartialEq,Eq,Debug,Hash)] #[derive(Clone,PartialEq,Eq,Debug,Hash)]
pub enum ErrorCode { pub enum ErrorCode {
Unknown = 0, WorkspaceNameInvalid = 0,
WorkspaceNameInvalid = 1, WorkspaceIdInvalid = 1,
WorkspaceIdInvalid = 2, AppColorStyleInvalid = 2,
AppColorStyleInvalid = 3, WorkspaceDescInvalid = 3,
WorkspaceDescInvalid = 4,
CurrentWorkspaceNotFound = 5,
AppIdInvalid = 10, AppIdInvalid = 10,
AppNameInvalid = 11, AppNameInvalid = 11,
ViewNameInvalid = 20, ViewNameInvalid = 20,
@ -228,8 +226,7 @@ pub enum ErrorCode {
ViewIdInvalid = 22, ViewIdInvalid = 22,
ViewDescInvalid = 23, ViewDescInvalid = 23,
ViewDataInvalid = 24, ViewDataInvalid = 24,
UserIdIsEmpty = 100, UserUnauthorized = 100,
UserUnauthorized = 101,
InternalError = 1000, InternalError = 1000,
RecordNotFound = 1001, RecordNotFound = 1001,
} }
@ -241,12 +238,10 @@ impl ::protobuf::ProtobufEnum for ErrorCode {
fn from_i32(value: i32) -> ::std::option::Option<ErrorCode> { fn from_i32(value: i32) -> ::std::option::Option<ErrorCode> {
match value { match value {
0 => ::std::option::Option::Some(ErrorCode::Unknown), 0 => ::std::option::Option::Some(ErrorCode::WorkspaceNameInvalid),
1 => ::std::option::Option::Some(ErrorCode::WorkspaceNameInvalid), 1 => ::std::option::Option::Some(ErrorCode::WorkspaceIdInvalid),
2 => ::std::option::Option::Some(ErrorCode::WorkspaceIdInvalid), 2 => ::std::option::Option::Some(ErrorCode::AppColorStyleInvalid),
3 => ::std::option::Option::Some(ErrorCode::AppColorStyleInvalid), 3 => ::std::option::Option::Some(ErrorCode::WorkspaceDescInvalid),
4 => ::std::option::Option::Some(ErrorCode::WorkspaceDescInvalid),
5 => ::std::option::Option::Some(ErrorCode::CurrentWorkspaceNotFound),
10 => ::std::option::Option::Some(ErrorCode::AppIdInvalid), 10 => ::std::option::Option::Some(ErrorCode::AppIdInvalid),
11 => ::std::option::Option::Some(ErrorCode::AppNameInvalid), 11 => ::std::option::Option::Some(ErrorCode::AppNameInvalid),
20 => ::std::option::Option::Some(ErrorCode::ViewNameInvalid), 20 => ::std::option::Option::Some(ErrorCode::ViewNameInvalid),
@ -254,8 +249,7 @@ impl ::protobuf::ProtobufEnum for ErrorCode {
22 => ::std::option::Option::Some(ErrorCode::ViewIdInvalid), 22 => ::std::option::Option::Some(ErrorCode::ViewIdInvalid),
23 => ::std::option::Option::Some(ErrorCode::ViewDescInvalid), 23 => ::std::option::Option::Some(ErrorCode::ViewDescInvalid),
24 => ::std::option::Option::Some(ErrorCode::ViewDataInvalid), 24 => ::std::option::Option::Some(ErrorCode::ViewDataInvalid),
100 => ::std::option::Option::Some(ErrorCode::UserIdIsEmpty), 100 => ::std::option::Option::Some(ErrorCode::UserUnauthorized),
101 => ::std::option::Option::Some(ErrorCode::UserUnauthorized),
1000 => ::std::option::Option::Some(ErrorCode::InternalError), 1000 => ::std::option::Option::Some(ErrorCode::InternalError),
1001 => ::std::option::Option::Some(ErrorCode::RecordNotFound), 1001 => ::std::option::Option::Some(ErrorCode::RecordNotFound),
_ => ::std::option::Option::None _ => ::std::option::Option::None
@ -264,12 +258,10 @@ impl ::protobuf::ProtobufEnum for ErrorCode {
fn values() -> &'static [Self] { fn values() -> &'static [Self] {
static values: &'static [ErrorCode] = &[ static values: &'static [ErrorCode] = &[
ErrorCode::Unknown,
ErrorCode::WorkspaceNameInvalid, ErrorCode::WorkspaceNameInvalid,
ErrorCode::WorkspaceIdInvalid, ErrorCode::WorkspaceIdInvalid,
ErrorCode::AppColorStyleInvalid, ErrorCode::AppColorStyleInvalid,
ErrorCode::WorkspaceDescInvalid, ErrorCode::WorkspaceDescInvalid,
ErrorCode::CurrentWorkspaceNotFound,
ErrorCode::AppIdInvalid, ErrorCode::AppIdInvalid,
ErrorCode::AppNameInvalid, ErrorCode::AppNameInvalid,
ErrorCode::ViewNameInvalid, ErrorCode::ViewNameInvalid,
@ -277,7 +269,6 @@ impl ::protobuf::ProtobufEnum for ErrorCode {
ErrorCode::ViewIdInvalid, ErrorCode::ViewIdInvalid,
ErrorCode::ViewDescInvalid, ErrorCode::ViewDescInvalid,
ErrorCode::ViewDataInvalid, ErrorCode::ViewDataInvalid,
ErrorCode::UserIdIsEmpty,
ErrorCode::UserUnauthorized, ErrorCode::UserUnauthorized,
ErrorCode::InternalError, ErrorCode::InternalError,
ErrorCode::RecordNotFound, ErrorCode::RecordNotFound,
@ -298,7 +289,7 @@ impl ::std::marker::Copy for ErrorCode {
impl ::std::default::Default for ErrorCode { impl ::std::default::Default for ErrorCode {
fn default() -> Self { fn default() -> Self {
ErrorCode::Unknown ErrorCode::WorkspaceNameInvalid
} }
} }
@ -311,59 +302,51 @@ impl ::protobuf::reflect::ProtobufValue for ErrorCode {
static file_descriptor_proto_data: &'static [u8] = b"\ static file_descriptor_proto_data: &'static [u8] = b"\
\n\x0cerrors.proto\"B\n\x0eWorkspaceError\x12\x1e\n\x04code\x18\x01\x20\ \n\x0cerrors.proto\"B\n\x0eWorkspaceError\x12\x1e\n\x04code\x18\x01\x20\
\x01(\x0e2\n.ErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03\ \x01(\x0e2\n.ErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03\
msg*\x80\x03\n\tErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x18\n\x14Worksp\ msg*\xc2\x02\n\tErrorCode\x12\x18\n\x14WorkspaceNameInvalid\x10\0\x12\
aceNameInvalid\x10\x01\x12\x16\n\x12WorkspaceIdInvalid\x10\x02\x12\x18\n\ \x16\n\x12WorkspaceIdInvalid\x10\x01\x12\x18\n\x14AppColorStyleInvalid\
\x14AppColorStyleInvalid\x10\x03\x12\x18\n\x14WorkspaceDescInvalid\x10\ \x10\x02\x12\x18\n\x14WorkspaceDescInvalid\x10\x03\x12\x10\n\x0cAppIdInv\
\x04\x12\x1c\n\x18CurrentWorkspaceNotFound\x10\x05\x12\x10\n\x0cAppIdInv\
alid\x10\n\x12\x12\n\x0eAppNameInvalid\x10\x0b\x12\x13\n\x0fViewNameInva\ alid\x10\n\x12\x12\n\x0eAppNameInvalid\x10\x0b\x12\x13\n\x0fViewNameInva\
lid\x10\x14\x12\x18\n\x14ViewThumbnailInvalid\x10\x15\x12\x11\n\rViewIdI\ lid\x10\x14\x12\x18\n\x14ViewThumbnailInvalid\x10\x15\x12\x11\n\rViewIdI\
nvalid\x10\x16\x12\x13\n\x0fViewDescInvalid\x10\x17\x12\x13\n\x0fViewDat\ nvalid\x10\x16\x12\x13\n\x0fViewDescInvalid\x10\x17\x12\x13\n\x0fViewDat\
aInvalid\x10\x18\x12\x11\n\rUserIdIsEmpty\x10d\x12\x14\n\x10UserUnauthor\ aInvalid\x10\x18\x12\x14\n\x10UserUnauthorized\x10d\x12\x12\n\rInternalE\
ized\x10e\x12\x12\n\rInternalError\x10\xe8\x07\x12\x13\n\x0eRecordNotFou\ rror\x10\xe8\x07\x12\x13\n\x0eRecordNotFound\x10\xe9\x07J\xee\x05\n\x06\
nd\x10\xe9\x07J\xe9\x06\n\x06\x12\x04\0\0\x18\x01\n\x08\n\x01\x0c\x12\ \x12\x04\0\0\x15\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\
\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\ \x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x16\n\x0b\n\x04\
\x12\x03\x02\x08\x16\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x17\n\x0c\n\ \x04\0\x02\0\x12\x03\x03\x04\x17\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x03\
\x05\x04\0\x02\0\x06\x12\x03\x03\x04\r\n\x0c\n\x05\x04\0\x02\0\x01\x12\ \x04\r\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0e\x12\n\x0c\n\x05\x04\0\
\x03\x03\x0e\x12\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x15\x16\n\x0b\n\ \x02\0\x03\x12\x03\x03\x15\x16\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\
\x04\x04\0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\ \x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\
\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\ \x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\
\x05\x04\0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\ \x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x15\x01\n\n\n\x03\x05\0\x01\
\x18\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x0e\n\x0b\n\x04\x05\0\x02\0\ \x12\x03\x06\x05\x0e\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x1d\n\x0c\n\
\x12\x03\x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\ \x05\x05\0\x02\0\x01\x12\x03\x07\x04\x18\n\x0c\n\x05\x05\0\x02\0\x02\x12\
\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\ \x03\x07\x1b\x1c\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x1b\n\x0c\n\
\x12\x03\x08\x04\x1d\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x18\n\ \x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x16\n\x0c\n\x05\x05\0\x02\x01\x02\
\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\x1b\x1c\n\x0b\n\x04\x05\0\x02\ \x12\x03\x08\x19\x1a\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x1d\n\x0c\n\
\x02\x12\x03\t\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x16\n\ \x05\x05\0\x02\x02\x01\x12\x03\t\x04\x18\n\x0c\n\x05\x05\0\x02\x02\x02\
\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x19\x1a\n\x0b\n\x04\x05\0\x02\x03\ \x12\x03\t\x1b\x1c\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x1d\n\x0c\n\
\x12\x03\n\x04\x1d\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x18\n\x0c\ \x05\x05\0\x02\x03\x01\x12\x03\n\x04\x18\n\x0c\n\x05\x05\0\x02\x03\x02\
\n\x05\x05\0\x02\x03\x02\x12\x03\n\x1b\x1c\n\x0b\n\x04\x05\0\x02\x04\x12\ \x12\x03\n\x1b\x1c\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\x04\x16\n\x0c\n\
\x03\x0b\x04\x1d\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x18\n\x0c\ \x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x10\n\x0c\n\x05\x05\0\x02\x04\x02\
\n\x05\x05\0\x02\x04\x02\x12\x03\x0b\x1b\x1c\n\x0b\n\x04\x05\0\x02\x05\ \x12\x03\x0b\x13\x15\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x0c\x04\x18\n\x0c\
\x12\x03\x0c\x04!\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x1c\n\ \n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x12\n\x0c\n\x05\x05\0\x02\x05\
\x0c\n\x05\x05\0\x02\x05\x02\x12\x03\x0c\x1f\x20\n\x0b\n\x04\x05\0\x02\ \x02\x12\x03\x0c\x15\x17\n\x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\x19\n\
\x06\x12\x03\r\x04\x16\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x10\n\ \x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x13\n\x0c\n\x05\x05\0\x02\x06\
\x0c\n\x05\x05\0\x02\x06\x02\x12\x03\r\x13\x15\n\x0b\n\x04\x05\0\x02\x07\ \x02\x12\x03\r\x16\x18\n\x0b\n\x04\x05\0\x02\x07\x12\x03\x0e\x04\x1e\n\
\x12\x03\x0e\x04\x18\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x12\n\ \x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x18\n\x0c\n\x05\x05\0\x02\
\x0c\n\x05\x05\0\x02\x07\x02\x12\x03\x0e\x15\x17\n\x0b\n\x04\x05\0\x02\ \x07\x02\x12\x03\x0e\x1b\x1d\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\x04\
\x08\x12\x03\x0f\x04\x19\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\ \x17\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x11\n\x0c\n\x05\x05\0\
\x13\n\x0c\n\x05\x05\0\x02\x08\x02\x12\x03\x0f\x16\x18\n\x0b\n\x04\x05\0\ \x02\x08\x02\x12\x03\x0f\x14\x16\n\x0b\n\x04\x05\0\x02\t\x12\x03\x10\x04\
\x02\t\x12\x03\x10\x04\x1e\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\ \x19\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\x13\n\x0c\n\x05\x05\0\
\x18\n\x0c\n\x05\x05\0\x02\t\x02\x12\x03\x10\x1b\x1d\n\x0b\n\x04\x05\0\ \x02\t\x02\x12\x03\x10\x16\x18\n\x0b\n\x04\x05\0\x02\n\x12\x03\x11\x04\
\x02\n\x12\x03\x11\x04\x17\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\ \x19\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\x13\n\x0c\n\x05\x05\0\
\x11\n\x0c\n\x05\x05\0\x02\n\x02\x12\x03\x11\x14\x16\n\x0b\n\x04\x05\0\ \x02\n\x02\x12\x03\x11\x16\x18\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x12\x04\
\x02\x0b\x12\x03\x12\x04\x19\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\ \x1b\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\x04\x14\n\x0c\n\x05\x05\0\
\x04\x13\n\x0c\n\x05\x05\0\x02\x0b\x02\x12\x03\x12\x16\x18\n\x0b\n\x04\ \x02\x0b\x02\x12\x03\x12\x17\x1a\n\x0b\n\x04\x05\0\x02\x0c\x12\x03\x13\
\x05\0\x02\x0c\x12\x03\x13\x04\x19\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\ \x04\x19\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\x13\x04\x11\n\x0c\n\x05\
\x13\x04\x13\n\x0c\n\x05\x05\0\x02\x0c\x02\x12\x03\x13\x16\x18\n\x0b\n\ \x05\0\x02\x0c\x02\x12\x03\x13\x14\x18\n\x0b\n\x04\x05\0\x02\r\x12\x03\
\x04\x05\0\x02\r\x12\x03\x14\x04\x18\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\ \x14\x04\x1a\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\x14\x04\x12\n\x0c\n\x05\
\x14\x04\x11\n\x0c\n\x05\x05\0\x02\r\x02\x12\x03\x14\x14\x17\n\x0b\n\x04\ \x05\0\x02\r\x02\x12\x03\x14\x15\x19b\x06proto3\
\x05\0\x02\x0e\x12\x03\x15\x04\x1b\n\x0c\n\x05\x05\0\x02\x0e\x01\x12\x03\
\x15\x04\x14\n\x0c\n\x05\x05\0\x02\x0e\x02\x12\x03\x15\x17\x1a\n\x0b\n\
\x04\x05\0\x02\x0f\x12\x03\x16\x04\x19\n\x0c\n\x05\x05\0\x02\x0f\x01\x12\
\x03\x16\x04\x11\n\x0c\n\x05\x05\0\x02\x0f\x02\x12\x03\x16\x14\x18\n\x0b\
\n\x04\x05\0\x02\x10\x12\x03\x17\x04\x1a\n\x0c\n\x05\x05\0\x02\x10\x01\
\x12\x03\x17\x04\x12\n\x0c\n\x05\x05\0\x02\x10\x02\x12\x03\x17\x15\x19b\
\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;

View File

@ -1,49 +1,49 @@
// Auto-generated, do not edit // Auto-generated, do not edit
mod view_update; mod view_update;
pub use view_update::*; pub use view_update::*;
mod view_delete; mod view_delete;
pub use view_delete::*; pub use view_delete::*;
mod app_query; mod app_query;
pub use app_query::*; pub use app_query::*;
mod workspace_delete; mod workspace_delete;
pub use workspace_delete::*; pub use workspace_delete::*;
mod observable; mod observable;
pub use observable::*; pub use observable::*;
mod errors; mod errors;
pub use errors::*; pub use errors::*;
mod workspace_update; mod workspace_update;
pub use workspace_update::*; pub use workspace_update::*;
mod app_create; mod app_create;
pub use app_create::*; pub use app_create::*;
mod workspace_query; mod workspace_query;
pub use workspace_query::*; pub use workspace_query::*;
mod event; mod event;
pub use event::*; pub use event::*;
mod view_create; mod view_create;
pub use view_create::*; pub use view_create::*;
mod workspace_user_detail; mod workspace_user_detail;
pub use workspace_user_detail::*; pub use workspace_user_detail::*;
mod workspace_create; mod workspace_create;
pub use workspace_create::*; pub use workspace_create::*;
mod app_update; mod app_update;
pub use app_update::*; pub use app_update::*;
mod view_query; mod view_query;
pub use view_query::*; pub use view_query::*;
mod app_delete; mod app_delete;
pub use app_delete::*; pub use app_delete::*;

View File

@ -5,12 +5,10 @@ message WorkspaceError {
string msg = 2; string msg = 2;
} }
enum ErrorCode { enum ErrorCode {
Unknown = 0; WorkspaceNameInvalid = 0;
WorkspaceNameInvalid = 1; WorkspaceIdInvalid = 1;
WorkspaceIdInvalid = 2; AppColorStyleInvalid = 2;
AppColorStyleInvalid = 3; WorkspaceDescInvalid = 3;
WorkspaceDescInvalid = 4;
CurrentWorkspaceNotFound = 5;
AppIdInvalid = 10; AppIdInvalid = 10;
AppNameInvalid = 11; AppNameInvalid = 11;
ViewNameInvalid = 20; ViewNameInvalid = 20;
@ -18,8 +16,7 @@ enum ErrorCode {
ViewIdInvalid = 22; ViewIdInvalid = 22;
ViewDescInvalid = 23; ViewDescInvalid = 23;
ViewDataInvalid = 24; ViewDataInvalid = 24;
UserIdIsEmpty = 100; UserUnauthorized = 100;
UserUnauthorized = 101;
InternalError = 1000; InternalError = 1000;
RecordNotFound = 1001; RecordNotFound = 1001;
} }

View File

@ -117,9 +117,7 @@ impl WorkspaceController {
set_current_workspace(&workspace.id); set_current_workspace(&workspace.id);
Ok(workspace) Ok(workspace)
} else { } else {
return Err(ErrorBuilder::new(ErrorCode::WorkspaceIdInvalid) return Err(WorkspaceError::workspace_id().context("Opened workspace id should not be empty"));
.msg("Opened workspace id should not be empty")
.build());
} }
} }
@ -172,9 +170,9 @@ impl WorkspaceController {
fn read_local_workspace(&self, workspace_id: String, user_id: &str, conn: &SqliteConnection) -> Result<Workspace, WorkspaceError> { fn read_local_workspace(&self, workspace_id: String, user_id: &str, conn: &SqliteConnection) -> Result<Workspace, WorkspaceError> {
// Opti: fetch single workspace from local db // Opti: fetch single workspace from local db
let mut repeated_workspace = self.read_local_workspaces(Some(workspace_id), user_id, conn)?; let mut repeated_workspace = self.read_local_workspaces(Some(workspace_id.clone()), user_id, conn)?;
if repeated_workspace.is_empty() { if repeated_workspace.is_empty() {
return Err(ErrorBuilder::new(ErrorCode::RecordNotFound).build()); return Err(WorkspaceError::not_found().context(format!("{} workspace not found", workspace_id)));
} }
debug_assert_eq!(repeated_workspace.len(), 1); debug_assert_eq!(repeated_workspace.len(), 1);
@ -294,7 +292,7 @@ fn set_current_workspace(workspace: &str) { KV::set_str(CURRENT_WORKSPACE_ID, wo
fn get_current_workspace() -> Result<String, WorkspaceError> { fn get_current_workspace() -> Result<String, WorkspaceError> {
match KV::get_str(CURRENT_WORKSPACE_ID) { match KV::get_str(CURRENT_WORKSPACE_ID) {
None => Err(ErrorBuilder::new(ErrorCode::CurrentWorkspaceNotFound).build()), None => Err(WorkspaceError::not_found().context("Current workspace not found or should call open workspace first")),
Some(workspace_id) => Ok(workspace_id), Some(workspace_id) => Ok(workspace_id),
} }
} }

View File

@ -1,5 +1,6 @@
use crate::helper::*; use crate::helper::*;
use flowy_ot::core::DeltaBuilder;
use flowy_workspace::entities::view::*; use flowy_workspace::entities::view::*;
#[test] #[test]
@ -34,11 +35,10 @@ fn view_open_doc() {
#[test] #[test]
fn view_update_doc() { fn view_update_doc() {
let test = ViewTest::new(); let test = ViewTest::new();
let new_data = DeltaBuilder::new().insert("flutter ❤️ rust").build().into_bytes();
let new_data = "123";
let request = SaveViewDataRequest { let request = SaveViewDataRequest {
view_id: test.view.id.clone(), view_id: test.view.id.clone(),
data: new_data.to_string(), data: new_data.clone(),
}; };
update_view_data(&test.sdk, request); update_view_data(&test.sdk, request);
@ -47,16 +47,17 @@ fn view_update_doc() {
view_id: test.view.id.clone(), view_id: test.view.id.clone(),
}; };
let doc = open_view(&test.sdk, request); let doc = open_view(&test.sdk, request);
assert_eq!(&doc.data, new_data); assert_eq!(doc.data, new_data);
} }
#[test] #[test]
fn view_update_big_doc() { fn view_update_big_doc() {
let test = ViewTest::new(); let test = ViewTest::new();
let new_data = "flutter ❤️ rust".repeat(1000000); let new_data = DeltaBuilder::new().insert(&"flutter ❤️ rust".repeat(1000000)).build().into_bytes();
let request = SaveViewDataRequest { let request = SaveViewDataRequest {
view_id: test.view.id.clone(), view_id: test.view.id.clone(),
data: new_data.to_string(), data: new_data.clone(),
}; };
update_view_data(&test.sdk, request); update_view_data(&test.sdk, request);