20 Aug 2016, 07:50

Error is for everyone

Writing Go has really taught me good manners in regards to error handling. Idiomatic Go handles errors right as they happen.

This got me thinking today. I was working on an AngularJS app and I thought it would be great to just pass errors.New onto the next stage of a Promise. It was then that I realized I could actually define a custom error type for use in my application, just like I could in Go.

The spec defines Error objects.

Instances of Error objects are thrown as exceptions when runtime errors occur. The Error objects may also serve as base objects for user-defined exception classes.

The key bit is that last sentence, which allows us to define our own Error objects.

// App Error is used for handling errors specific to our
// problem domain.
function appError(msg) {
    const err = Error(msg);

    err.name = "App Error"

    return err;
}

Since I’m working with Angular, I created a factory for my custom Error and called it appError.

function factory {
    function appError(msg) {
        const err = Error(msg);

        err.name = "App Error";

        return err;
    }

    return appError;
}

angular.module('myApp', []).factory('appError', factory);

Now I can include the appError factory wherever I need it and have a custom error type for my app. I find this especially useful when combined with $log. I use $log to send logs to Loggly, and I can see my custom App Errors right in the console.

11 Aug 2016, 08:43

meet quasimodo

Quasimodo is a little tool I wrote for easy publishing of Hugo sites to S3.

As joshuaboelter mentioned on reddit, the AWS CLI has the sync command that allows for easy uploads to S3. The sync command is great. I’ve used it before.

In terms of effort, I don’t think it was significantly harder than it would have been to just script the CLI. I wrote the first version pretty quickly. The CLI version of Quasimodo isn’t exactly a one liner either, because he checks to see if the bucket is properly configured to host a static site.

Also, when I wrote Quasimodo, I had in the back of my mind the scenario where I switch from S3 to something else. At that point, I could just give him subcommands for every provider and keep using the same program. To me, Quasimodo could publish Hugo sites to anywhere.

Anyways, that’s Quasimodo. Check him out on github.