Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core 13.19.0 sync errors changes #1386

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ class AppConfiguration {
/// These can be the same conceptual app developed for different platforms, or
/// significantly different client side applications that operate on the same data - e.g. an event managing
/// service that has different clients apps for organizers and attendees.
@Deprecated("localAppName is not used.")
final String? localAppName;

/// The [localAppVersion] can be specified, if you wish to distinguish different client versions of the
/// same application.
@Deprecated("localAppVersion is not used.")
final String? localAppVersion;

/// Enumeration that specifies how and if logged-in User objects are persisted across application launches.
Expand Down
157 changes: 43 additions & 114 deletions lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -614,32 +614,26 @@ class ClientResetError extends SyncError {

/// The [ClientResetError] has error code of [SyncClientErrorCode.autoClientResetFailure]
/// when a client reset fails and `onManualResetFallback` occurs. Otherwise, it is [SyncClientErrorCode.unknown]
@Deprecated("Use errorCode property")
SyncClientErrorCode get code => SyncClientErrorCode.fromInt(codeValue);

/// The [SyncSessionErrorCode] value indicating the type of the sync error.
/// This property will be [SyncSessionErrorCode.unknown] if `onManualResetFallback` occurs on client reset.
@Deprecated("Use errorCode property")
SyncSessionErrorCode get sessionErrorCode => SyncSessionErrorCode.fromInt(codeValue);

@Deprecated("ClientResetError constructor is deprecated and will be removed in the future")
ClientResetError(
ClientResetError._(
String message, {
App? app,
SyncErrorCategory category = SyncErrorCategory.client,
int? errorCodeValue,
this.backupFilePath,
this.originalFilePath,
String? detailedMessage,
}) : _app = app,
super(
message,
category,
errorCodeValue ?? SyncClientErrorCode.autoClientResetFailure.code,
detailedMessage: detailedMessage,
);
super._(message, SyncErrorCode.autoClientResetFailure);

@override
String toString() {
return "ClientResetError message: $message category: $category code: $code isFatal: $isFatal";
return "ClientResetError message: $message code: $errorCode isFatal: $isFatal";
}

/// Initiates the client reset process.
Expand All @@ -660,52 +654,34 @@ class ClientResetError extends SyncError {
/// {@category Sync}
class SyncError extends RealmError {
/// The numeric code value indicating the type of the sync error.
@Deprecated("Use property code")
final int codeValue;

/// If true the received error is fatal.
final bool isFatal = false;
/// Type of the sync error.
final SyncErrorCode errorCode;

/// The category of the sync error
final SyncErrorCategory category;

/// Detailed error message.
/// In case of server error, it contains the link to the server log.
final String? detailedMessage;

@Deprecated("SyncError constructor is deprecated and will be removed in the future")
SyncError(String message, this.category, this.codeValue, {this.detailedMessage}) : super(message);

/// Creates a specific type of [SyncError] instance based on the [category] and the [code] supplied.
@Deprecated("This method is deprecated and will be removed in the future")
static SyncError create(String message, SyncErrorCategory category, int code, {bool isFatal = false}) {
switch (category) {
case SyncErrorCategory.client:
final SyncClientErrorCode errorCode = SyncClientErrorCode.fromInt(code);
if (errorCode == SyncClientErrorCode.autoClientResetFailure) {
return ClientResetError(message);
}
return SyncClientError(message, category, errorCode, isFatal: isFatal);
case SyncErrorCategory.connection:
return SyncConnectionError(message, category, SyncConnectionErrorCode.fromInt(code), isFatal: isFatal);
case SyncErrorCategory.session:
return SyncSessionError(message, category, SyncSessionErrorCode.fromInt(code), isFatal: isFatal);
case SyncErrorCategory.webSocket:
return SyncWebSocketError(message, category, SyncWebSocketErrorCode.fromInt(code));
case SyncErrorCategory.system:
case SyncErrorCategory.unknown:
default:
return GeneralSyncError(message, category, code);
}
}
@Deprecated("No sync error categories")
final SyncErrorCategory category = SyncErrorCategory.system;

SyncError._(String message, this.errorCode)
: codeValue = errorCode.code,
super(message);

/// As a specific [SyncError] type.
T as<T extends SyncError>() => this as T;

@override
String toString() {
return "SyncError message: $message category: $category code: $codeValue";
return "SyncError message: $message code: $errorCode";
}
}

/// An error type that describes a session-level error condition.
/// {@category Sync}
@Deprecated("Use SyncError")
class SyncClientError extends SyncError {
/// If true the received error is fatal.
final bool isFatal;
Expand All @@ -718,9 +694,8 @@ class SyncClientError extends SyncError {
String message,
SyncErrorCategory category,
SyncClientErrorCode errorCode, {
String? detailedMessage,
this.isFatal = false,
}) : super(message, category, errorCode.code, detailedMessage: detailedMessage);
}) : super._(message, SyncErrorCode.unknown);

@override
String toString() {
Expand All @@ -730,6 +705,7 @@ class SyncClientError extends SyncError {

/// An error type that describes a connection-level error condition.
/// {@category Sync}
@Deprecated("Use SyncError")
class SyncConnectionError extends SyncError {
/// If true the received error is fatal.
final bool isFatal;
Expand All @@ -742,9 +718,8 @@ class SyncConnectionError extends SyncError {
String message,
SyncErrorCategory category,
SyncConnectionErrorCode errorCode, {
String? detailedMessage,
this.isFatal = false,
}) : super(message, category, errorCode.code, detailedMessage: detailedMessage);
}) : super._(message, SyncErrorCode.unknown);

@override
String toString() {
Expand All @@ -754,6 +729,7 @@ class SyncConnectionError extends SyncError {

/// An error type that describes a session-level error condition.
/// {@category Sync}
@Deprecated("Use SyncError")
class SyncSessionError extends SyncError {
/// If true the received error is fatal.
final bool isFatal;
Expand All @@ -766,49 +742,25 @@ class SyncSessionError extends SyncError {
String message,
SyncErrorCategory category,
SyncSessionErrorCode errorCode, {
String? detailedMessage,
this.isFatal = false,
}) : super(message, category, errorCode.code, detailedMessage: detailedMessage);
}) : super._(message, SyncErrorCode.unknown);

@override
String toString() {
return "SyncSessionError message: $message category: $category code: $code isFatal: $isFatal";
}
}

/// Network resolution error
///
/// This class is deprecated and it will be removed. The sync errors caused by network resolution problems
/// will be received as [SyncWebSocketError].
@Deprecated("Use SyncWebSocketError instead")
class SyncResolveError extends SyncError {
/// The numeric value indicating the type of the network resolution sync error.
SyncResolveErrorCode get code => SyncResolveErrorCode.fromInt(codeValue);

SyncResolveError(
String message,
SyncErrorCategory category,
SyncResolveErrorCode errorCode,
) : super(message, category, errorCode.index);

@override
String toString() {
return "SyncResolveError message: $message category: $category code: $code";
}
}

/// Web socket error
@Deprecated("Use WebSocketError")
class SyncWebSocketError extends SyncError {
/// The numeric value indicating the type of the web socket error.
SyncWebSocketErrorCode get code => SyncWebSocketErrorCode.fromInt(codeValue);

@Deprecated("SyncWebSocketError constructor is deprecated and will be removed in the future")
SyncWebSocketError(
SyncWebSocketError._(
String message,
SyncErrorCategory category,
SyncWebSocketErrorCode errorCode, {
String? detailedMessage,
}) : super(message, category, errorCode.code, detailedMessage: detailedMessage);
SyncWebSocketErrorCode errorCode,
) : super._(message, SyncErrorCode.unknown);

@override
String toString() {
Expand All @@ -817,17 +769,15 @@ class SyncWebSocketError extends SyncError {
}

/// A general or unknown sync error
@Deprecated("Use SyncError")
class GeneralSyncError extends SyncError {
/// The numeric value indicating the type of the general sync error.
int get code => codeValue;

@Deprecated("GeneralSyncError constructor is deprecated and will be removed in the future")
GeneralSyncError(
GeneralSyncError._(
String message,
SyncErrorCategory category,
int code, {
String? detailedMessage,
}) : super(message, category, code, detailedMessage: detailedMessage);
int code,
) : super._(message, SyncErrorCode.unknown);

@override
String toString() {
Expand All @@ -836,6 +786,7 @@ class GeneralSyncError extends SyncError {
}

/// General sync error codes
@Deprecated("Use SyncErrorCode")
enum GeneralSyncErrorCode {
/// Unknown Sync error code
unknown(9999);
Expand Down Expand Up @@ -875,58 +826,36 @@ class CompensatingWriteInfo {
/// by the server.
/// {@category Sync}
class CompensatingWriteError extends SyncError {

/// The [CompensatingWriteError] has error code of [SyncSessionErrorCode.compensatingWrite]
@Deprecated("Use errorCode property instead")
SyncSessionErrorCode get code => SyncSessionErrorCode.compensatingWrite;

/// The list of the compensating writes performed by the server.
late final List<CompensatingWriteInfo>? compensatingWrites;

CompensatingWriteError._(
String message, {
String? detailedMessage,
this.compensatingWrites,
}) : super(message, SyncErrorCategory.session, SyncSessionErrorCode.compensatingWrite.code, detailedMessage: detailedMessage);
}) : super._(message, SyncErrorCode.compensatingWrite);

@override
String toString() {
return "CompensatingWriteError message: $message category: $category code: $code. ${compensatingWrites ?? ''}";
return "CompensatingWriteError message: $message code: $errorCode. ${compensatingWrites ?? ''}";
}
}

/// @nodoc
extension SyncErrorInternal on SyncError {
static SyncError createSyncError(SyncErrorDetails error, {App? app}) {
final errorCode = SyncErrorCode.fromInt(error.code);
if (error.isClientResetRequested) {
//Client reset can be requested with isClientResetRequested disregarding the SyncClientErrorCode and SyncSessionErrorCode values
return ClientResetError(error.message,
app: app,
category: error.category,
errorCodeValue: error.code,
originalFilePath: error.originalFilePath,
backupFilePath: error.backupFilePath,
detailedMessage: error.detailedMessage);
}

switch (error.category) {
case SyncErrorCategory.client:
final errorCode = SyncClientErrorCode.fromInt(error.code);
return SyncClientError(error.message, error.category, errorCode, detailedMessage: error.detailedMessage, isFatal: error.isFatal);
case SyncErrorCategory.connection:
final errorCode = SyncConnectionErrorCode.fromInt(error.code);
return SyncConnectionError(error.message, error.category, errorCode, detailedMessage: error.detailedMessage, isFatal: error.isFatal);
case SyncErrorCategory.session:
final errorCode = SyncSessionErrorCode.fromInt(error.code);
if (errorCode == SyncSessionErrorCode.compensatingWrite) {
return CompensatingWriteError._(error.message, detailedMessage: error.detailedMessage, compensatingWrites: error.compensatingWrites);
}
return SyncSessionError(error.message, error.category, errorCode, detailedMessage: error.detailedMessage, isFatal: error.isFatal);
case SyncErrorCategory.webSocket:
final errorCode = SyncWebSocketErrorCode.fromInt(error.code);
return SyncWebSocketError(error.message, error.category, errorCode, detailedMessage: error.detailedMessage);
case SyncErrorCategory.system:
case SyncErrorCategory.unknown:
default:
return GeneralSyncError(error.message, error.category, error.code, detailedMessage: error.detailedMessage);
return ClientResetError._(error.message,
app: app, errorCodeValue: error.code, originalFilePath: error.originalFilePath, backupFilePath: error.backupFilePath);
} else if (errorCode == SyncErrorCode.compensatingWrite) {
return CompensatingWriteError._(error.message, compensatingWrites: error.compensatingWrites);
}
return SyncError._(error.message, errorCode);
}
}
Loading
Loading