From c1305ada65f337c18eda5437f16f8e3af714e44c Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sun, 30 Oct 2016 15:57:45 +0800 Subject: [PATCH 1/4] Rename MigrationNeededException to PhoneMigrationException There are different kind of MIGRATE errors that could be thrown by the Telegram API, as evidenced by this recent change: https://github.com/sochix/TLSharp/commit/b06f8a8e1174f0d2580f36039054adb25d62403e So this rename tries to make it consistent to the new exception names: * FILE_MIGRATE_x -> FileMigrationException * USER_MIGRATE_y -> UserMigrationException * PHONE_MIGRATE_z -> PhoneMigrationException --- TLSharp.Core/Network/MtProtoSender.cs | 6 +++--- TLSharp.Core/TelegramClient.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TLSharp.Core/Network/MtProtoSender.cs b/TLSharp.Core/Network/MtProtoSender.cs index 1f22aeb..108baf1 100644 --- a/TLSharp.Core/Network/MtProtoSender.cs +++ b/TLSharp.Core/Network/MtProtoSender.cs @@ -279,7 +279,7 @@ namespace TLSharp.Core.Network { var resultString = Regex.Match(errorMessage, @"\d+").Value; var dcIdx = int.Parse(resultString); - throw new MigrationNeededException(dcIdx); + throw new PhoneMigrationException(dcIdx); } else if (errorMessage.StartsWith("FILE_MIGRATE_")) { @@ -495,11 +495,11 @@ namespace TLSharp.Core.Network } } - internal class MigrationNeededException : Exception + internal class PhoneMigrationException : Exception { internal int DC { get; private set; } - internal MigrationNeededException(int dc) + internal PhoneMigrationException(int dc) : base ($"Your phone number is registered to a different DC: {dc}. Please migrate.") { DC = dc; diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 0c6f3c7..03083f4 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -124,7 +124,7 @@ namespace TLSharp.Core completed = true; } - catch (MigrationNeededException ex) + catch (PhoneMigrationException ex) { await ReconnectToDcAsync(ex.DC); } From a521466bb02c97eac845240e59511248aff8886e Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sun, 30 Oct 2016 16:04:32 +0800 Subject: [PATCH 2/4] Create common abstract DataCenterMigrationException We can abstract the DC property to a common abstract class so have a bit of less code and we join these 3 classes together semantically. --- TLSharp.Core/Network/MtProtoSender.cs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/TLSharp.Core/Network/MtProtoSender.cs b/TLSharp.Core/Network/MtProtoSender.cs index 108baf1..6966028 100644 --- a/TLSharp.Core/Network/MtProtoSender.cs +++ b/TLSharp.Core/Network/MtProtoSender.cs @@ -495,36 +495,37 @@ namespace TLSharp.Core.Network } } - internal class PhoneMigrationException : Exception + internal abstract class DataCenterMigrationException : Exception { internal int DC { get; private set; } + protected DataCenterMigrationException(string msg, int dc) : base (msg) + { + DC = dc; + } + } + + internal class PhoneMigrationException : DataCenterMigrationException + { internal PhoneMigrationException(int dc) - : base ($"Your phone number is registered to a different DC: {dc}. Please migrate.") + : base ($"Your phone number is registered to a different DC: {dc}. Please migrate.", dc) { - DC = dc; } } - internal class FileMigrationException : Exception + internal class FileMigrationException : DataCenterMigrationException { - internal int DC { get; private set; } - internal FileMigrationException(int dc) - : base ($"File is located on a different DC: {dc}. Please migrate.") + : base ($"File is located on a different DC: {dc}. Please migrate.", dc) { - DC = dc; } } - internal class UserMigrationException : Exception + internal class UserMigrationException : DataCenterMigrationException { - internal int DC { get; private set; } - internal UserMigrationException(int dc) - : base($"User is located on a different DC: {dc}. Please migrate.") + : base($"User is located on a different DC: {dc}. Please migrate.", dc) { - DC = dc; } } } \ No newline at end of file From e1ff4bb75b8d418d0c65fd165542b5bd452becad Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sun, 30 Oct 2016 16:16:55 +0800 Subject: [PATCH 3/4] Bring back report message to Migration exceptions When refactoring recently the PHONE_MIGRATE_X error wrt exception handling [1] I removed the dubious/obsolete "settings" part, but I mistakenly removed the URL which tells library consumers that if they face this exception, it's actually a bug of the library that they should report. [1] https://github.com/sochix/TLSharp/commit/77867b44e626aedfba58cf9729100e3cc1a808a8 --- README.md | 4 ++-- TLSharp.Core/Network/MtProtoSender.cs | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bdde200..301a0a2 100644 --- a/README.md +++ b/README.md @@ -203,9 +203,9 @@ Contributing is highly appreciated! #### What API layer is supported? The latest one - 57. Thanks to Afshin Arani for his TLGenerator -#### I get an error MIGRATE_X? +#### I get a xxxMigrationException or a MIGRATE_X error! -TLSharp library should automatically handle this errors. If you see such errors, pls create a new issue. +TLSharp library should automatically handle these errors. If you see such errors, please open a new Github issue with the details (include a stacktrace, etc.). #### I get an exception: System.IO.EndOfStreamException: Unable to read beyond the end of the stream. All test methos except that AuthenticationWorks and TestConnection return same error. I did every thing including setting api id and hash, and setting server address.- diff --git a/TLSharp.Core/Network/MtProtoSender.cs b/TLSharp.Core/Network/MtProtoSender.cs index 6966028..cadaad4 100644 --- a/TLSharp.Core/Network/MtProtoSender.cs +++ b/TLSharp.Core/Network/MtProtoSender.cs @@ -499,7 +499,10 @@ namespace TLSharp.Core.Network { internal int DC { get; private set; } - protected DataCenterMigrationException(string msg, int dc) : base (msg) + private const string REPORT_MESSAGE = + " See: https://github.com/sochix/TLSharp#i-get-an-error-migrate_x"; + + protected DataCenterMigrationException(string msg, int dc) : base (msg + REPORT_MESSAGE) { DC = dc; } @@ -508,7 +511,7 @@ namespace TLSharp.Core.Network internal class PhoneMigrationException : DataCenterMigrationException { internal PhoneMigrationException(int dc) - : base ($"Your phone number is registered to a different DC: {dc}. Please migrate.", dc) + : base ($"Phone number registered to a different DC: {dc}.", dc) { } } @@ -516,7 +519,7 @@ namespace TLSharp.Core.Network internal class FileMigrationException : DataCenterMigrationException { internal FileMigrationException(int dc) - : base ($"File is located on a different DC: {dc}. Please migrate.", dc) + : base ($"File located on a different DC: {dc}.", dc) { } } @@ -524,7 +527,7 @@ namespace TLSharp.Core.Network internal class UserMigrationException : DataCenterMigrationException { internal UserMigrationException(int dc) - : base($"User is located on a different DC: {dc}. Please migrate.", dc) + : base($"User located on a different DC: {dc}.", dc) { } } From 5161d38456104c48fc468a4d636f96b51519e605 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sun, 30 Oct 2016 16:33:29 +0800 Subject: [PATCH 4/4] MigrationExceptions: update URL Previous commit[1] made the anchor change its name due to changing slightly the content of the README around the MIGRATE problem. [1] e1ff4bb75b8d418d0c65fd165542b5bd452becad --- TLSharp.Core/Network/MtProtoSender.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TLSharp.Core/Network/MtProtoSender.cs b/TLSharp.Core/Network/MtProtoSender.cs index cadaad4..d46a68e 100644 --- a/TLSharp.Core/Network/MtProtoSender.cs +++ b/TLSharp.Core/Network/MtProtoSender.cs @@ -500,7 +500,7 @@ namespace TLSharp.Core.Network internal int DC { get; private set; } private const string REPORT_MESSAGE = - " See: https://github.com/sochix/TLSharp#i-get-an-error-migrate_x"; + " See: https://github.com/sochix/TLSharp#i-get-a-xxxmigrationexception-or-a-migrate_x-error"; protected DataCenterMigrationException(string msg, int dc) : base (msg + REPORT_MESSAGE) {