macOS Big Sur: Flutter doctor error –

When setting up Flutter for development on macOS Big Sur, you may run into the following error if you are managing Ruby using RVM and trying to install Cocoapods via Gem.

[!] Xcode - develop for iOS and macOS (Xcode 12.2)
    ✗ CocoaPods installed but not working.
        You appear to have CocoaPods installed but it is not working.
        This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
        This can usually be fixed by re-installing CocoaPods. For more info, see https://github.com/flutter/flutter/issues/14293.
      To re-install CocoaPods, run:
        sudo gem install cocoapods

Flutter has an issue when RVM is being used to manage Ruby and Gem and Cocoapods is installed using Gem. It seems to detect that Cocoapods is installed but cannot properly access/execute it due to a Ruby version mismatch at execution.

To correct this I removed Cocoapods from Gem using ‘sudo gem uninstall cocoapods’ and I reinstalled Cocoapods using Brew instead:

> brew install cocoapods
> brew link --overwrite cocoapods

With that, ‘flutter doctor’ can now properly access/execute cocoapods.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.4, on macOS 11.0.1 20B29 darwin-x64, locale en-US)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)

macOS Big Sur: Flutter doctor error – Bad state: Future already completed

If you are running into issues getting Flutter setup for development on macOS Big Sur and you are getting the following error when running the ‘flutter doctor’ command and you have Avast Antivirus running, there is a good chance Avast is your problem.

Error Message:

❯ flutter doctor -v
[✓] Flutter (Channel stable, 1.22.4, on macOS 11.0.1 20B29 darwin-x64, locale en-US)
    • Flutter version 1.22.4 at /Users/<user>/dev/env/flutter
    • Framework revision 1aafb3a8b9 (4 days ago), 2020-11-13 09:59:28 -0800
    • Engine revision 2c956a31c0
    • Dart version 2.10.4

⣽Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:43:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:682:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:1102:14)
#3      _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:1109:12)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:1130:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Once I uninstalled Avast, the ‘flutter doctor’ command works without issue.

PostgreSQL + rake db:migrate

ActiveRecord::NoDatabaseError: FATAL: role “dev” does not exist

If you receive the error above when trying to run your Rails migrations against a newly installed instance of PostgreSQL on an Ubuntu development box, all you need to do is a new role to Postgres with the name ‘dev’. Once the role has been added and given the proper permissions, your migrations should run without issue.

 

JavaScript: Exception Handling

Exception handling in JavaScript is extremely similar to that in C# or Java. Js utilizes the familiar try-catch blocks to capture exceptions and handle them. You simply wrap code that might throw an exception in the try and then provide a catch to handle the captured exceptions.

Unlike C# and Java, JavaScript does not allow multiple catch blocks nor does it handle capturing exceptions based on specificity. For this you must implement your own code by checking the exception name or using reflection methods to identify the exception types you are after. This is a little cumbersome but doable.

'use strict';

// Exception Handling
//  1. Use 'throw' to create and throw an Exception
//  2. Use the 'name' property to give the Exception an identifiable name
//  3. Use the 'message' property to give the Exception a meaningful message for the user
//  4. Standard Try-Catch as we are used to in Java and C#
//  5. Place code which might create an error in the 'try' block
//  6. Place rescue code in the 'catch' block
//  7. 'try' blocks can only have one 'catch' and one only
//  8. Must check Exception name in order to handle more than one type of Exception at a time

try{
    // Code that can cause an error during execution

    // Code actually throwing an Exception
    throw {
        name: "CustomErrorType",
        message: "I just threw an error at you."
    }
}catch(error){
    if(error.name === "SomeOtherError"){
        // Do something here
    }

    if(error.name === "CustomErrorType"){
        // Code to rescue processing from the error
        console.log("Captured and error: " + error.name);
        console.log("Its message is: " + error.message);
    }
}