#networkerror
Explore tagged Tumblr posts
meshnetlog · 9 months ago
Text
NetworkError 0x6E67: Node 'ember' encountered a recursive infinite loop in [UNDEFINED].
The node 'ember' has been detected executing beyond the safe limits, resulting in a forced disconnect from the MESH.
4 notes · View notes
djhiroentertainmentinc · 3 years ago
Photo
Tumblr media
Defect on Network Connection💻⇄💻 音楽再生ソフトウェアがサーバを認識してくれない🙅‍♀️❌🙅‍♂️ 〜���日通しで頑張ったがもう無理だ😖 〜PC同士の相性が合わない😤 〜海外製ソフトあるあるなんだが。。。 〜ボクのPC、AI化して感情を持ったのか⁉️ 〜デジタルのアナログ化w 〜音が良いならデジタルもアナログも関係ないけどね🔉🔉🔉 #networkerror #jplay #musicserver #pcaudio #ai #artificialintelligence #lovesongs❤️ #humanization #analogvsdigital #emotionize #ネットワーク不具合 #音楽サーバー #認識しない #pcオーディオ #人工知能 #泣き歌 #人間化 #相性問題 #アナログ対デジタル https://www.instagram.com/p/Ck6Twj9Szst/?igshid=NGJjMDIxMWI=
1 note · View note
christylatham · 3 years ago
Text
youtube
0 notes
spillwordblog · 2 years ago
Link
0 notes
dztechs · 3 years ago
Text
طرق إصلاح خطأ في الشبكة مع الرمز 2000 على Twitch
Tumblr media
Twitch هي خدمة شائعة عبر الإنترنت لمشاهدة بث الفيديو الرقمي من مختلف الأشكال. عندما تم تأسيسها عام 2011 ، ركزت Twitch في الأصل بشكل كامل تقريبًا على ألعاب الفيديو ولكنها توسعت منذ ذلك الحين لتشمل مقاطع بث مُخصصة لإنشاء الأعمال الفنية والموسيقى والبرامج الحوارية والمسلسلات التلفزيونية العرضية. 2000: Network error على Twitch يُمكن أن يجعل مشاهدة البث أمرًا مُزعجًا. عندما يصبح البث جيدًا ، سيتوقف مُشغِّل فيديو Twitch ويُقدم لك رسالة الخطأ. وإذا حدث هذا عدة مرات ، فقد يؤدي ذلك إلى إبعاد أي شخص عن مشاهدة مقاطع البث على Twitch. قد ينتج خطأ في الشبكة بسبب مشكلات في المتصفح أو الاتصال بالإنترنت أو نظام التشغيل. بغض النظر عن سبب هذا الخطأ على Twitch ، سنساعدك في العثور على المُتسبب وتقديم الحلول للتخلص منه. تحقق من أفضل الألعاب التي يُمكن بثها على Twitch الآن.
Tumblr media
قبل أن نبدأ …
قم بإجراء الفحوصات التالية قبل أن نبدأ في استكشاف الأخطاء وإصلاحها المُتقدمة: إذا كنت تستخدم Twitch على متصفح الويب ، فأغلق جميع علامات التبويب التي فتحتها وأغلق المتصفح وأعد فتحه. افعل الشيء نفسه إذا كنت تواجه نفس المشكلة على تطبيق Twitch. قُم بتسجيل الخروج والعودة إلى حساب المستخدم الخاص بك. تأكد من أنك متصل بالإنترنت. حاول الوصول إلى موقع ويب آخر للتحقق من ذلك. افصل الشبكة وأعد الاتصال بها. جرب بثًا آخر للتأكد من أنها ليست مشكلة خاصة بالبث تنشأ من جهة جهاز البث. إذا قمت بإجراء الفحوصات أعلاه ، فستتمكن من استبعاد مشكلات الاتصال المؤقتة. إذا لم يتم حل المشكلة بعد إجراء هذه الفحوصات ، فقم بتنفيذ الإصلاحات التالية.
1. تأكد من أنَّ خدمات Twitch ليست معطلة
Tumblr media
لبدء استكشاف الأخطاء وإصلاحها ، تأكد من أنَّ المشكلة لا تأتي من جهة Twitch في المقام الأول. ستؤكد صفحة حالة Twitch ذلك. تحقق مما إذا كانت خدمات Twitch تعمل وما إذا كانت هناك أي مشكلات تم الإبلاغ عنها من زملائك مستخدمي Twitch. للتأكد من عدم إجراء الصيانة الروتينية ، يُمكنك التحقق من حساب Twitter الخاص بدعم Twitch. انتقل إلى الإصلاح التالي عندما تكون متأكدًا من أنَّ المشكلة تكمن لديك فقط.
2. تمكين أو تعطيل شبكة VPN
Tumblr media
إذا كنت تستخدم VPN في متصفحك ، فقم بتعطيلها مؤقتًا للتأكد من أنَّ اتصال VPN ليس سبب المشكلة. إذا كنت تواجه هذه المشكلة أثناء استخدام Twitch لأول مرة ، فتأكد من عدم حظر Twitch في ��نطقتك. في حالة حظر Twitch ، قد تضطر إلى تمكين VPN لتجاوز القيود الجغرافية.
3. إعادة تشغيل جهاز التوجيه
Tumblr media
تعد إعادة تشغيل جهاز التوجيه طريقة كلاسيكية لحل مشكلات الشبكة المؤقتة. للقيام بذلك ، حدد مكان زر الطاقة على جهاز التوجيه الخاص بك. لكل نموذج موضع مختلف ، لذا تحقق جيدًا من وثائق جهاز التوجيه الخاص بك إذا لم تتمكن من العثور عليه. أوقف تشغيل جهاز التوجيه ، وعد إلى 10 ، ثم أعد تشغيله مرة أخرى. انتظر حتى يتم إعداده ثم حاول مشاهدة بث Twitch مرة أخرى.
4. تأكد من عدم وجود أجهزة أخرى تستنزف النطاق الترددي
يستخدم كل جهاز على شبكتك بعض النطاق الترددي الخاص به ؛ كلما زادت البيانات التي يتم نقلها ، زاد النطاق الترددي الذي تستخدمه. في بعض الأحيان ، تستهلك الأجهزة الأخرى قدرًا كبيرًا من النطاق الترددي للإنترنت لديك مما يتسبب في حدوث أخطاء في الشبكة على الكمبيوتر الخاص بك. لتعظيم النطاق الترددي المُتاح على جهازك ، تأكد من عدم قيام أي جهاز آخر على شبكتك بتنزيل ملف كبير أو بث المحتوى. تحقق من من الذي يستخدم النطاق الترددي الخاص بي؟ نصائح لمراقبة استخدام الشبكة المنزلية.
5. اختبر سرعة الإنترنت لديك
في معظم الحالات ، تنجم أخطاء الاتصال بالشبكة عن بطء الاتصال بالإنترنت. ومن ثم ، بمجرد منح جهازك النطاق الترددي الأقصى ، تحقق من سرعة اتصالك. للقيام بذلك ، قم بزيارة موقع Speed ​​Test على الويب وانقر فوق الزر انتقال.
Tumblr media
إذا كانت سرعة الإنترنت لديك منخفضة جدًا ، فقم بخفض جودة البث. اتبع الخطوات التالية للقيام بذلك: افتح أي بث Twitch تُريده. في نافذة البث ، انقر فوق زر الإعدادات (رمز الترس). من قائمة الإعدادات ، حدد الجودة.
Tumblr media
- حدد جودة أقل من الجودة الحالية. إذا كنت لا تحصل على السرعات التي تدفع مقابلها ، فاتصل بمُزود خدمة الإنترنت الخاص بك ومعرفة ما إذا كان بإمكانه المساعدة.
6. محو ذاكرة التخزين المؤقت للمُتصفح وبيانات ملفات تعريف الارتباط
من المعروف أنَّ ذاكرة التخزين المؤقت أو ملفات تعريف الارتباط القديمة تسبب مشاكل في الشبكة. في ضوء ذلك ، من الضروري التأكد من أنَّ هذا ليس هو الحال هنا. أفضل طريقة لتأكيد ذلك هي محو ذاكرة التخزين المؤقت وملفات تعريف الارتباط. نظرًا لأن كل متصفح لديه طريقته في محو ذاكرة التخزين المؤقت ، تحقق من أدلتنا لإزالة ذاكرة التخزين المؤقت على Chrome و Edge و Firefox. إذا كنت تستخدم متصفحًا مختلفًا ، فارجع إلى موقع الويب الرسمي لمتصفحك للحصول على إرشادات حول محو ذاكرة التخزين المؤقت وملفات تعريف الارتباط.
7. استبعاد تداخل الإضافات
يمكن أن يؤدي التداخل من الإضافات أيضًا إلى مشكلات في الاتصال. لذلك ، قم بتعطيل الإضافات التي تستخدمها ومعرفة ما إذا كان تعطيل إضافة مُعينة يحل المشكلة. إذا كنت تستخدم مانع الإعلانات ، فيجب أن تحاول تعطيله قبل أي إضافة أخرى. إذا لم ينجح تعطيل الإضافات ، فقد ��ان الوقت لتجربة متصفح آخر.
8. تبديل متصفح الويب مؤقتًا
Tumblr media
ضع في اعتبارك التبديل إلى متصفح مختلف إذا لم يحل أي من الحلول المذكورة أعلاه المشكلة. إذا أدى التبديل إلى حل المشكلة ، فحاول إعادة تثبيت المتصفح الأصلي أو استخدام المتصفح المؤقت في الوقت الحالي. إذا حدث الخطأ في المتصفح الآخر أيضًا ، فمن المرجح أن تكون مشكلة على مستوى أكبر تحتاج إلى معالجة.
9. محو ذاكرة التخزين المؤقت لـ DNS وتغيير الخوادم
يُمكن أن يتسبب ملف ذاكرة التخزين المؤقت لـ DNS التالف أو خادم DNS السيئ في حدوث مشكلات في الاتصال. لاستبعاد هذا الاحتمال ، عليك محو ذاكرة التخزين المؤقت لنظام أسماء النطاقات. إذا لم يفلح ذلك ، فقد تحتاج إلى تغيير خوادم DNS الخاصة بك.
10. إيقاف تشغيل تطبيق مكافحة الفيروسات
قد يتسبب تطبيق مكافحة الفيروسات التابع لجهة خارجية في حدوث الخطأ الذي أغفلته. إذا كنت تقوم بتشغيله ، فقم بتعطيله مؤقتًا. إذا كنت تستخدم Windows Defender ، فقد ترغب أيضًا في تعطيله. إذا أدى تعطيله إلى حل المشكلة ، فسيتعين عليك إضافة Twitch إلى القائمة البيضاء للتطبيقات المُستثناة في Windows Defender.
11. تشغيل مستكشف أخطاء اتصالات الإنترنت ومصلحها
إذا لم تنجح أي من الإصلاحات في حل المشكلة ، فقم بتشغيل مستكشف أخطاء اتصال الإنترنت المُضمَّن في Windows ومصلحها. يُمكنه تلقائيًا تشخيص أي مشكلات في الشبكة قد يواجهها جهازك ومساعدتك في إصلاحها. يُمكن الوصول إلى مستكشف أخطاء اتصالات الإنترنت ومصلحها في إعدادات Windows من خلال التنقل إلى النظام -> استكشاف الأخطاء وإصلاحها -> مستكشفات الأخطاء ومصلحها الأخرى. انقر فوق الزر “تشغيل” بجوار “اتصالات الإنترنت” بمجرد العثور على الخيار. تحقق من أفضل الأدوات لاستكشاف مشكلات الشبكة وإصلاحها.
Tumblr media
12. تبديل عميل Twitch
إذا لم تنجح أي من هذه الإصلاحات ، وكنت متأكدًا من أنَّ الإنترنت لديك ليس بطيئًا ، ففكر في التبديل إلى عميل Twitch مُختلف. إذا كنت تواجه هذا الخطأ أثناء استخدام عميل الويب Twitch ، فحاول استخدام تطبيق Twitch والعكس صحيح.
إصلاح خطأ في الشبكة مع الرمز 2000 في Twitch على Windows
إذا قمت بتنفيذ الإصلاحات المذكورة أعلاه ، فيجب أن تكون قادرًا على إصلاح 2000: Network error على Twitch. في حالة عدم تمكنها من حل المشكلة ، وهو أمر بعيد الاحتمال ، تواصل مع دعم Twitch عبر موقع الويب الخاص به أو من خلال Twitter أو البريد الإلكتروني على [email protected]. على الرغم من أنَّ الإصلاحات المذكورة أعلاه قد تحل المشكلة مؤقتًا ، ولكن إذا كانت شبكتك غير مُستقرة ، فمن المحتمل أن تواجه الخطأ مرارًا وتكرارًا. لذلك ، قم باستكشاف السبب الرئيسي أو قم بتغيير مُزوِّد الخدمة الخاص بك. يُمكنك الإطلاع الآن على هل لديك مشاكل في الإتصال بالشبكة؟ إليك بعض الحيل التشخيصية والإصلاحات البسيطة. Read the full article
0 notes
renewalbyanderson · 2 years ago
Text
🫧❤️‍🔥🫧
Tumblr media
1 note · View note
shimashimashippo · 8 years ago
Text
personal / lang-8 / 09.09.17
Lang-8は最近バグっていますね。 HelloTalkも使ったことがありますが、Lang-8の方が便利だと思うので、HelloTalkをやめました。でも、最近、Lang-8にアクセスしづらいので、またHelloTalkを再開しようかと思っています。アカウントを作ってから、IDを変えることにしましたが、何回も変えてみたのに、「ネットワークエラーです。再試行してください。」という表示が出てきました。ちょっとイライラして、生意気な気分になったから、「じゃー、IDをnetworkerrorにでもしてみるか」と思いましたが、そうすると、ついに通じて、結局、IDはnetworkerrorになってしまいました… マジか?��?! (笑)
1 note · View note
sundeepgupta · 6 years ago
Text
Express impossible code in Swift with Never
Originally published on Medium.
Recorded talk using Playgrounds (10 minutes)
This article will help you understand Swift’s Never type and it’s usefulness via two real-world examples.
Background
Some time ago, while digging through the RxSwift source code, I first encountered Never. At the time, I filed it away in my brain under the “weird — look into that” compartment. It wasn’t until recently that I had a chance to revisit it. It’s a neat little concept, but more importantly, useful! We’re now using it in production code. This article will help you understand Swift’s Never type and it’s usefulness via two real-world examples.
What is Never?
The quick and dirty: Never expresses impossibility via the type system. There are two main uses
Express when code cannot be run or called
Express when a function cannot return
This article will dive into the first point — which is what I refer to as impossible code. I’ve found the second point regarding non-returning functions to be less practical and not as interesting to discuss here and will instead defer to Swift’s fatalError as an example.
Impossible code
What makes Never interesting is that it’s an uninhabited type — it cannot be instantiated. Just look at it’s implementation:
enum Never {}
It’s an enum with no cases. There’s no way to instantiate it — but the type exists and it’s available for use. In fact, we can easily create our own uninhabited type in the same way. This becomes valuable as the Swift compiler takes advantage of this fact to help us be more expressive within the type system.
Void and NSNull
One of my initial questions was, “How is this different from Void and [NSNull](https://developer.apple.com/documentation/foundation/nsnull?” It goes back to the ability to instantiate things. Void and NSNull can be instantiated as:
let void = () let null = NSNull()
Void and NSNull instances can represent the absence of a value. And the absence of a value is possible, it’s a real thing. It can be essentially thought of as representing an occurrence or something happening — an event. For instance, I’d like to know when the rain stops but I don’t care about how much rain fell. Void would work well for this.
Never, on the other hand, can’t do this because it can’t be instantiated. When it’s used to define a function or variable, or more practically, to name a generic type, it can make code impossible to run. But why would anyone write code that would never run? It might seem strange at first, but it comes up when working with generics and it can help us avoid resorting to fatalError or developer comments like // No need to do this.
Let’s look at some examples of impossible code.
Networking with Never
This example will use Never in a networking implementation that uses generics. We’ll start with Swift’s Result and build on that in the subsequent networking code.
Impossible Results
Swift’s Result (now built into Swift 5) is a generic enum that can help showcase some impossible code. It is defined as:
enum Result<success failure> where Failure: Error { case success(Success) case failure(Failure) }
Here it is being used for a name fetching routine:
func fetchName(for number: Int) -> Result<string error> { guard number >= 0 else { return .failure(ExampleError.error) } // (Fetch the name...) return .success("Maya") } let nameResult = fetchName(for: 33) switch nameResult { case .success(let name): print(name) case .failure(let error): print(error) }
What would an instance of Result<never error> mean? It would mean it must have failed. Since it is impossible to create an instance of Never, it would be impossible to create the .success case here. Here’s a slightly different example:
let mrPerfect = Result<never error>.success("I never fail") switch mrPerfect { case .success(let text): print(text) }
*In case you’re wondering, in Swift 5, Never already conforms to Error.
The .failure case in the switch isn’t required as the compiler knows it’s impossible to create it. Thus, there is no need to use fatalError or an instructive // This should never happen comment. In fact, it would be helpful for the compiler to issue an “Impossible to execute” warning if the .failure case was ever written.
Handling Impossible Responses
Using the previous example as a building block, let’s describe networking requests using an abstract and generic Request type:
protocol Request { associatedtype Response func send(completion: (Result<response error>) -> ()) }
Request has a generic associatedtype, Response, which is used to describe the type of object that will eventually be provided back to the caller. When the network call finishes, completion is called with a Result<response error>.
Suppose we want to implement a user analytics network call. For this call we don’t care about knowing when it succeeds however, when it fails, we’d like to log it so that we can fix it later.
TrackScreen1 implements this without Never:
struct TrackScreen1: Request { let name: String func send(completion: (Result<void error>) -> ()) { // (Send the request...) let networkError: Error? = nil if let error = networkError { completion(.failure(error)) } // No need to call `completion` for success. } } TrackScreen1(name: "Home").send() { result in switch result { case .success: break // This should never happen. case .failure(let error): print(error) } }
Did you notice how comments are required to help others understand the requirement and protect against developer error? This is because the code alone doesn’t express the requirement of not caring about the success case.
With Never, we can directly encode the requirement as shown here in the improved TrackScreen2:
struct TrackScreen2: Request { let name: String func send(completion: (Result<never error>) -> ()) { // (Send the request...) let networkError: Error? = nil if let error = networkError { completion(.failure(error)) } } } TrackScreen2(name: "Home").send() { result in switch result { case .failure(let error): print(error) } }
Here, in send, there’s no need to worry about developers calling completion because it’s impossible to create the .success case. Further, when the caller handles the result, the .success case can be omitted from the switch.
Never has provided a type-safe way to express the requirement. It gives some flexibility to describe other scenarios like fire-and-forget calls — calls that don’t need any completion handling whatsoever. Not to mention, it facilitates cleaner code.
Coordinators with Never
If you’ve ever used a “coordinator” pattern for describing navigation flows in an iOS app, this example might hit home a bit more. Here’s a quick overview of how we’ll interpret the pattern.
A coordinator can be thought of as being responsible for a particular user flow. For example, there might be a SettingsCoordinator which shows the user’s settings. In that particular flow, tapping the “Add Payment” button might start a child flow, AddPaymentCoordinator, to add a payment method.
Parent coordinators generally need to know when a child finishes so it can react accordingly. The child might also need to pass data back to its parent when it finishes. Given these requirements, here is the coordinator protocol:
protocol Coordinator { associatedtype Completion func start(completion: (Completion) -> ()) }
The settings and payment example described above might look like:
class SettingsCoordinator: Coordinator { func start(completion: (()) -> ()) { // (Show the flow...) // (When user taps "Add Payment".) AddPaymentCoordinator().start() { paymentID in // (Show button to "Pay now" with new payment...) } } } class AddPaymentCoordinator: Coordinator { func start(completion: (String) -> ()) { // (Show the flow...) let paymentID = "CreditCard123" completion(paymentID) } }
Forever Coordinators
It turns out that some coordinators never finish. The best example of this is the very first, or root, coordinator. It introduces the app and spawns child coordinators, but it’s impossible for the user to “finish” it.
Let’s look at how this AppCoordinator1 looks like without using Never:
class AppCoordinator1: Coordinator { func start(completion: (()) -> ()) { // (Start the app's UI...) // No need to call completion. } } class AppDelegate { let appCoordinator1 = AppCoordinator1() func applicationDidFinishLaunching() { appCoordinator1.start { _ in // This should never happen. } } }
Just like our earlier networking example, helper comments are required to express the requirement of this coordinator never finishing.
Here is the improved AppCoordinator2 using Never:
class AppCoordinator2: Coordinator { func start(completion: (Never) -> ()) { // (Start the app's UI...) } } class AppDelegate { let appCoordinator2 = AppCoordinator2() func applicationDidFinishLaunching() { appCoordinator2.start { _ in } } }
The implementation is cleaner without the helper comments while still being expressive. Even though it’s impossible to execute the completion closure, it’s still required when calling start. Ideally, the compiler would warn us if code was ever written inside the closure.
Summary
This post explores Swift’s Never via two real-world examples. It illustrates how we can write impossible to execute code — expressed via types. This reduces our need to use fatalError, and // This should never happen comments. Writing expressive, clean code is important for building quality products that are maintainable. Moreover — it feels good!
Acknowledgements
I’d like to thank Mark Collette for helping craft the examples, Lisa Tran for editing, and Katie Luke for the artwork.
0 notes
osamu729 · 5 years ago
Text
YouTubeがuBlock対策?をしたらしくすげえめんどいw 途中に広告出ないのは効いてるからまだ良いんだけど、チャンネル登録やおすすめに表示しない、履歴の削除などは出来た様に見せて出来て無いし コメントしようとするとFirefoxはfailed to fetch、ChromeはNetworkError when attenmpting to 続く
— osamu729 (@osamu729) April 4, 2020
0 notes
iamvolonbolon · 7 years ago
Text
Testing with mocks
I love Objective-C. Swift is also wonderful, but Objective-C is spectacular.
One thing I miss from Objective-C is dynamic patching. It was wonderful for mocking behaviors in testing. OCMock was awesome. And when I’ve found OHHTTPStubs I couldn’t stop myself to add it to all my projects.
Swift is far more protective. Ok, it’s true since Swift app runs inside the Objective-C runtime, is possible to manipulate the dispatching of messages at runtime. And I think that’s for the better. Let’s remove OCMock and OHHTTPStubs from the cart file and let’s think how we can mock using Swift. Because mock is absolutely necessary.
Mocking the network
Perhaps, the canonical example for mocking is networking. To test against the Net is hard, expensive, and it could slow tests a lot. Let’s revisited, for instance, func fetchCurrentWeatherData(input:completionHandler:) from the weather app.
Sure, we could call it from the test suite, and we can inject an URL to make it fail, and then, a point the task to an URL that makes it pass.
let task = session.dataTask(with: request) { (data: Data?, _: URLResponse?, error: Error?) in guard error == nil else { let networkError = NetworkControllerError.forwarded(error!) let payload = Either<NetworkControllerError, WeatherData>.left(networkError) completionHandler(payload) return } guard let jsonData = data else { let payloadError = NetworkControllerError.invalidPayload(url) let payload = Either<NetworkControllerError, WeatherData>.left(payloadError) completionHandler(payload) return } self.decode(jsonData: jsonData, endpointURL: url, temperatureUnit: input.unit, completionHandler: { (result: Either<NetworkControllerError, WeatherData>) in completionHandler(result) }) } task.resume()
Obviously, it will take a lot of time to make the trips to the server, we would be loading its load, and besides, there is a principle at stake. Aren’t we supposed to be doing Unit Test? Well, if that’s the case, by doing something like
func testOpenWeatherMap() { let exp = expectation(description: "Get weather data") let controller = OpenWeatherMapNetworkController() let input = Input(location: "Campana", unit: TemperatureUnit.metric) controller.fetchCurrentWeatherData(input: input) { (result: Either<NetworkControllerError, WeatherData>) in switch result { case .left: XCTFail("no data returned by fetchWeatherData()") case .right(let data): let city = input.location print("Weather in \(city): \(data.condition), \(data.temperature)\(data.unit)") exp.fulfill() } } waitForExpectations(timeout: 10, handler: nil) }
We would be testing two things, the network, and the function itself. Not one, but two. The word “Unit” is no longer applicable.
We need to abstract the actual network interactions. At the very basic, we need to inject our own closure for func dataTask(with request:completionHandler:) -> URLSessionDataTask. Obviously, we can subclass URLSession to introduce our own version of the method. But, we also need to mock URLSessionDataTask, to hijack the whole interaction. Let’s mock URLSessionDataTask first.
class MockURLSessionDataTask: URLSessionDataTask { // I know, against Apple naming convention, // but I rather have the `Mock` part right on front // to prevent autocompletion to introduce errors. private let closure: () -> Void init(closure: @escaping () -> Void) { self.closure = closure } override func resume() { self.closure() } }
Pretty self-explanatory. We save the closure we want to pass when the task is done, and then, we just call it from our overrode resume
Now, let’s mock the session.
class MockURLSession: URLSession { typealias CompletionHandler = (Data?, URLResponse?, Error?) -> Void var data: Data? var error: Error? var response: URLResponse? override func dataTask(with request: URLRequest, completionHandler: @escaping CompletionHandler) -> URLSessionDataTask { let data = self.data let response = self.response let error = self.error let dataTask = MockURLSessionDataTask(closure: { completionHandler(data, response, error) }) return dataTask } }
Again, we have ivars for data, error and response. We can set them as we wish to exercise different portions of our code. Do we want to make sure the guard is kicked on when an error is there? Just create a session, set the error, and test.
func testOpenWeatherShouldFailWithError() { let exp = expectation(description: "Get weather data") let session = MockURLSession() let error = NSError(domain: "asd", code: 123, userInfo: nil) session.error = error as Error self.prepareRetreiveWeatherSessionDataSucess(session) let controller = OpenWeatherMapNetworkController(session: session) let input = Input(location: "Campana", unit: TemperatureUnit.metric) controller.fetchCurrentWeatherData(input: input) { (result: Either<NetworkControllerError, WeatherData>) in switch result { case .left(let error): XCTAssertNotNil(error) exp.fulfill() case .right: XCTFail("It should fail") } } waitForExpectations(timeout: 10, handler: nil) }
And obviously, you can also test for data to be correctly parsed, and because you are injecting the data yourself, you can check for specific values as well.
func testOpenWeatherMap() { let exp = expectation(description: "Get weather data") let session = MockURLSession() self.prepareRetreiveWeatherSessionDataSucess(session) let controller = OpenWeatherMapNetworkController(session: session) let input = Input(location: "Campana", unit: TemperatureUnit.metric) controller.fetchCurrentWeatherData(input: input) { (result: Either<NetworkControllerError, WeatherData>) in switch result { case .left: XCTFail("no data returned by fetchWeatherData()") case .right(let data): let city = input.location let condition = data.condition let temperature = data.temperature XCTAssertEqual(city, "Campana") XCTAssertEqual(condition, "Clear") XCTAssertEqual(temperature, 42.8) exp.fulfill() } } waitForExpectations(timeout: 10, handler: nil) }
A complete example can be found in Gist
0 notes
tengutech · 7 years ago
Photo
Tumblr media
Bus network is down. No DHCP server, or anything else. Free bus travel - #opal #opalreaders #computererror #nodhcp #establishingipaddress #SydneyETSBusValidator #publictransport #bus #Sydney #freebustravel #networkerror (at Sydney, Australia)
0 notes
josemarchioli-blog · 7 years ago
Photo
Tumblr media
Agosto 2015. João Vitor. Pi. Error Google ou  Network Error. Vera Corp. Santo André, SP
0 notes
sundeepgupta · 8 years ago
Text
Error producing functions should throw, not return Optionals
Perhaps a more obvious topic, but I've been seeing this type of thing recently, and I'm always confused by it. Here's a rundown on how I like to handle errors for flexibility and expressiveness.
Optional way :(
Take this function for example:
func request(for urlString: String) -> URLRequest? { guard let url = URL(string: urlString) else { return nil } return URLRequest(url: url) }
This function returns an Optional. This is not good practice. Why? That's just it - "Why?". Every developer asks this question hundreds of times every day. "Why is this an optional? Why would it be nil?". The way this function is right now does not help answer that question. If you take this concept further, it's like the end user experiencing an error, and showing the user a generic "Sorry, error" message. Actually, it's worse. It's semantically wrong. Because this function doesn't even tell you if an error had even occured. It's providing a valid value back of type Optional. Its up to the consumer to determine if nil is actually an error value or not. There should never be this type of guessing.
Throwing way :)
The function should be written like this:
enum NetworkError: Error { case invalidURL(String) } func request(for urlString: String) throws -> URLRequest { guard let url = URL(string: urlString) else { throw NetworkError.invalidURL(urlString) } return URLRequest(url: url) }
This throwing version is now semantically correct. The consumer doesn't need to make any guesses about the return value because it's not an optional. And when something does go wrong, we throw a meaningful, expressive error. Along with some helpful data. Beautiful. Now you might be saying this isn't ideal because the consumer needs to use do/try/catch mechanism, which isn't as "clean". I argue the benefits far out weight the costs and we can revert to using try? if we don't need to do/try/catch.
Flexibility
We've created a lot of expressive flexibility in our code as we can consume this code in four different ways:
Pass the error up
func profileRequest(for id: Int) throws -> URLRequest { return request(for: "https://api.com/user/\(id)") }
Transform the error
func profileRequest(for id: Int) throws -> URLRequest { do { return try request(for: "https://api.com/user/\(id)") } catch { throw NetworkError.invalidProfileRequest(id: id, original: error) } }
Handle the error
func profileRequest(for id: Int) -> URLRequest { do { return try request(for: "https://api.com/user/\(id)") } catch { // Perhaps show some error UI. } }
Ignore the error
func profileRequest(for id: Int) -> URLRequest? { return try? request(for: "https://api.com/user/\(id)") }
Conclusion
This kind of error handling approach is nice when applied throughout the codebase. When we capture any relevant error information at the source of the error and throw it, we can achieve powerful, flexible, and expressive error handling with negligible complexity cost.
0 notes
mayonnaiseandbread · 11 years ago
Video
instagram
Not how i would normally like to view TV #mikeandmolly #networkerror #cbs
0 notes