How to use the clime.ExpectedError function in clime

To help you get started, we’ve selected a few clime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github evias / nem2-sandbox / src / commands / convert / serial.ts View on Github external
async execute(options: CommandOptions) {
        let bytes;
        try {
            bytes = OptionsResolver(options,
                'bytes',
                () => { return ''; },
                'Enter a hexadecimal bytes list: ');
        } catch (err) {
            console.log(options);
            throw new ExpectedError('Enter a valid input');
        }

        // Transaction byte size data
        const sizeLength        = 8;
        const signatureLength   = 128;
        const publicKeyLength   = 64;
        const versionLength     = 4;
        const typeLength        = 4;
        const feeLength         = 16;
        const deadlineLength    = 16;

        // Transaction byte data positions
        const signatureOffset = sizeLength;
        const publicKeyOffset = signatureOffset + signatureLength;
        const versionOffset = publicKeyOffset + publicKeyLength;
        const typeOffset = versionOffset + versionLength;
github evias / nem2-sandbox / src / commands / transaction / transferMultisig.ts View on Github external
async execute(options: CommandOptions) {
        await this.setupConfig();

        let numCosig;
        try {
            numCosig = OptionsResolver(options, 'numCosig', () => { return ''; },
                'Enter a maximum number of cosignatories: ');
            numCosig = parseInt(numCosig);
        } catch (err) {
            throw new ExpectedError('Enter a valid maximum number of cosignatories');
        }

        // add a block monitor
        this.monitorBlocks();
        return await this.createMultisigTransfer(numCosig);
    }
github nemtech / nem2-cli / src / validators / publicKey.validator.ts View on Github external
validate(value: string, context?: ValidationContext): void {
        if (value.length !== 64 || !/^[0-9a-fA-F]+$/.test(value)) {
            throw new ExpectedError('Public key should be a 64 characters hexadecimal string');
        }
    }
}
github evias / nem2-sandbox / src / commands / reader / addressAlias.ts View on Github external
peerUrl = OptionsResolver(options,
                'peerUrl',
                () => { return ''; },
                'Enter a peerUrl: (Ex.: http://localhost:3000)');

            namespaceName = OptionsResolver(options,
                'namespaceName',
                () => { return ''; },
                'Enter a namespaceName: (Ex.: evias)');

            if (!namespaceName.length) {
                throw new Error("Namespace name is obligatory");
            }
        } catch (err) {
            console.log(options);
            throw new ExpectedError('Enter a valid input');
        }

        if (peerUrl.length) {
            this.endpointUrl = peerUrl;
        }

        const namespaceHttp = new NamespaceHttp(this.endpointUrl);

        let text = '';
        text += chalk.green('Peer:\t') + chalk.bold(this.endpointUrl) + '\n';
        text += '-'.repeat(20) + '\n\n';

        const namespaceId = new NamespaceId(namespaceName);
        const observer = namespaceHttp.getLinkedAddress(namespaceId).subscribe((apiResponses) => {

            let address = apiResponses as Address;
github nemtech / nem2-cli / src / service / mosaic.service.ts View on Github external
static validate(value: string) {
        const mosaicParts = value.split('::');
        let valid = true;
        try {
            if (isNaN(+mosaicParts[1])) {
                valid = false;
            }
            const ignored = new Mosaic(this.getMosaicId(mosaicParts[0]),
                UInt64.fromUint(+mosaicParts[1]));
        } catch (err) {
            valid = false;
        }
        if (!valid) {
            throw new ExpectedError('Mosaic should be in the format (mosaicId(hex)|@aliasName)::absoluteAmount,' +
                ' (Ex: sending 1 cat.currency, @cat.currency::1000000)');
        }
    }
github nemtech / nem2-cli / src / validators / password.validator.ts View on Github external
validate(value: string, context?: ValidationContext): void {
        try {
             const ignored = new Password(value);
         } catch (error) {
              throw new ExpectedError('Password should have a minimum of 8 characters');
         }
     }
}
github nemtech / nem2-cli / src / validators / binary.validator.ts View on Github external
validate(value: number, context?: ValidationContext): void {
        if (value !== 0 && value !== 1) {
            throw new ExpectedError('The value must be 0 or 1');
        }
    }
}
github nemtech / nem2-cli / src / validators / mosaicId.validator.ts View on Github external
validate(value: string, context?: ValidationContext): void {
        try {
            const ignored = new MosaicId(value);
        } catch (err) {
            throw new ExpectedError('Enter a mosaic id in hexadecimal format. Example: 941299B2B7E1291C');
        }
    }
}
github nemtech / nem2-cli / src / validators / block.validator.ts View on Github external
validate(value: string, context?: ValidationContext): void {
        let valid = true;
        if (value === '0') {
            valid = false;
        }
        try {
            UInt64.fromNumericString(value);
        } catch (e) {
            valid = false;
        }
        if (!valid) {
            throw new ExpectedError('The block height must be a positive integer');
        }
    }
}
github evias / nem2-sandbox / src / commands / wallet / balance.ts View on Github external
private readAccount(addressOrPub: string): Address
    {
        if (addressOrPub.length === 40) {
            return Address.createFromRawAddress(addressOrPub);
        }
        else if (addressOrPub.length === 64) {
            return Address.createFromPublicKey(addressOrPub, NetworkType.MIJIN_TEST);
        }

        throw new ExpectedError("parameter addressOrPub must be either of 40 or 64 characters.");
    }

clime

The command-line interface framework for TypeScript.

MIT
Latest version published 6 months ago

Package Health Score

62 / 100
Full package analysis

Popular clime functions