diff --git a/src/commands/contract.js b/src/commands/contract.js index c004761e..63523ecc 100644 --- a/src/commands/contract.js +++ b/src/commands/contract.js @@ -28,7 +28,12 @@ import { nodeOption, jsonOption, gasOption } from '../arguments'; const callArgs = new Argument('[args]', 'JSON-encoded arguments array of contract call') .argParser((argsText) => { - const args = JSON.parse(argsText); + let args; + try { + args = JSON.parse(argsText); + } catch (error) { + throw new CliError(`Can't parse contract arguments: ${error.message}`); + } if (!Array.isArray(args)) throw new CliError(`Call arguments should be an array, got ${argsText} instead`); return args; }) diff --git a/test/contract.js b/test/contract.js index 5898daa0..5dc1036f 100644 --- a/test/contract.js +++ b/test/contract.js @@ -23,6 +23,7 @@ import { expect } from 'chai'; import { decode } from '@aeternity/aepp-sdk'; import { executeProgram, getSdk, WALLET_NAME } from './index'; import contractProgram from '../src/commands/contract'; +import CliError from '../src/utils/CliError'; const executeContract = (args) => executeProgram(contractProgram, args); @@ -117,6 +118,16 @@ describe('CLI Contract Module', function contractTests() { fs.unlinkSync(descrPath); fs.unlinkSync(contractBytecodeFile); }); + + it('throws error if arguments invalid', async () => { + await expect(executeContract([ + 'deploy', + WALLET_NAME, '--password', 'test', + '--contractSource', contractSourceFile, + '[3', + '--json', + ])).to.be.rejectedWith(CliError, 'Can\'t parse contract arguments: Unexpected end of JSON input'); + }); }); describe('Call', () => {