All files / npm-pack-all/utils utils.index.js

100% Statements 23/23
83.33% Branches 5/6
100% Functions 5/5
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 395x   1x     1x 1x     1x 1x 1x 1x       5x 10x 34x 34x   2x 1x         5x 6x 6x 6x 1x 1x   5x 5x      
module.exports.CliError = class CliError extends Error {
    constructor(flag, value, message) {
        super();
 
        // Maintains proper stack trace for where our error was thrown (only available on V8)
        Eif (Error.captureStackTrace) {
            Error.captureStackTrace(this, CliError);
        }
 
        this.name = `CliInputError`;
        this.cliFlag = flag;
        this.cliValue = value;
        this.message = message;
    }
};
 
module.exports.safetyDecorator = function(wrapped) {
    return function() {
        try {
            wrapped.apply(this, arguments);
        } catch (e) {
            if (e.message.toLowerCase().includes(`no such file`)) return;
            throw e;
        }
    };
};
 
module.exports.shellExecDecorator = function(wrapped) {
    return function() {
        const result = wrapped.apply(this, arguments);
        if (result.code !== 0) {
            console.error(JSON.stringify(result));
            throw new Error(result.stderr);
        }
        console.info(result.stdout);
        return result;
    };
};