/* @flow */

import type Site from './site';

export default function compose(...funcs
        : Array<(site : Site) => Site|Promise<Site>>)
        : (site : Site) => Promise<Site> {
    return async (site : Site) => {
        return await callAndRecurse(site, funcs);
    };
}

async function callAndRecurse(site : Site,
        funcs : Array<(site : Site) => Site|Promise<Site>>)
        : Promise<Site> {
    if (funcs.length === 0) {
        return Promise.resolve(site);
    }
    const [func, ...remainingFunc] = funcs;
    let nextSite;
    try {
        nextSite = await func(site);
    } catch (err) {
        console.error(`Error in transform function: ${func.name}`);
        console.error(err);
        throw err;
    }
    return callAndRecurse(nextSite, remainingFunc);
}

@@ -37,16 +37,55 @@
 ./site';
+%0Aimport %7B getLogger %7D from './logging';
 %0A%0Aexport
@@ -652,27 +652,65 @@
         cons
-ole
+t log = getLogger('compose');%0A        log
 .error(%60Erro
@@ -762,15 +762,11 @@
     
-console
+log
 .err

Use logger to log errors in compose