Skip to content

Commit

Permalink
Added some improved error messages around using the correct contract …
Browse files Browse the repository at this point in the history
…identifiers to help users debug.
  • Loading branch information
thekevinbrown committed May 17, 2019
1 parent b2ce1a5 commit 6fae66a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ export const pathToIdentifier = (filePath: string) => filePath.substr(0, filePat
export const build = async (contractPath: string) => {
// Get the base filename from path and log status
const basename = path.basename(contractPath, '.cpp');
console.log(basename);
// Compile contract at path
await compileContract(contractPath);
// Generate Typescript definitions for contract
Expand Down Expand Up @@ -394,9 +393,18 @@ export const compileContract = async (contractPath: string) => {
spinner.create(`Compiling contract`);

const basename = path.basename(contractPath, '.cpp');

if (!(await exists(contractPath))) {
spinner.fail(
`Couldn't locate contract at ${contractPath}. Are you sure used the correct contract identifier when trying to build the contract?`
);

throw new Error("Contract doesn't exist on disk.");
}

const outputPath = outputPathForContract(contractPath);

// Pull docker images
// Run the compile contract script inside our docker container.
await docker
.command(
// Arg 1 is filename, arg 2 is contract name.
Expand Down
17 changes: 16 additions & 1 deletion src/contracts/contractDeployer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as path from 'path';
import { readFile as readFileCallback } from 'fs';
import { readFile as readFileCallback, exists as existsCallback } from 'fs';
import { promisify } from 'util';
import { Serialize } from 'eosjs';
import * as ecc from 'eosjs-ecc';

const exists = promisify(existsCallback);
const readFile = promisify(readFileCallback);

import { Contract } from './contract';
Expand Down Expand Up @@ -45,11 +46,25 @@ export class ContractDeployer {
'compiled_contracts',
`${contractIdentifier}.abi`
);

if (!(await exists(abiPath))) {
throw new Error(
`Couldn't find ABI at ${abiPath}. Are you sure you used the correct contract identifier?`
);
}

const wasmPath = path.join(
ConfigManager.outDir,
'compiled_contracts',
`${contractIdentifier}.wasm`
);

if (!(await exists(wasmPath))) {
throw new Error(
`Couldn't find WASM file at ${wasmPath}. Are you sure you used the correct contract identifier?`
);
}

// Read resources files for paths
let abi = JSON.parse(await readFile(abiPath, 'utf8'));
const wasm = await readFile(wasmPath);
Expand Down

0 comments on commit 6fae66a

Please sign in to comment.