Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add try catch to JSON parse with a nice error message #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ export function loadAllDeployments(
fileName,
onlyABIAndAddress
);

if(!contracts){
console.error('Could not load deployments.')
return
}

all[chainIdFound][name] = {
name,
chainId: chainIdFound,
Expand All @@ -135,6 +141,12 @@ export function loadAllDeployments(
undefined,
networkChainId
);

if(!contracts){
console.error('Could not load deployments.')
return all
}

all[networkChainId][networkName] = {
name: networkName,
chainId: networkChainId,
Expand Down Expand Up @@ -212,9 +224,28 @@ function loadDeployments(
for (const fileName of fileNames) {
if (fileName.substr(fileName.length - 5) === '.json') {
const deploymentFileName = path.join(deployPath, fileName);
let deployment = JSON.parse(
fs.readFileSync(deploymentFileName).toString()
);


let deployment:any;

try{
deployment = JSON.parse(
fs.readFileSync(deploymentFileName).toString()
);

}catch(e){
console.error(`Failed to parse ${deploymentFileName}`)

console.error(e)
return
}

if(!deployment){
throw new Error(`Undefined Deployment:,${deploymentFileName}`)
return
}


if (!deployment.address && deployment.networks) {
if (truffleChainId && deployment.networks[truffleChainId]) {
// TRUFFLE support
Expand Down Expand Up @@ -256,6 +287,11 @@ export function addDeployments(
expectedChainId,
truffleChainId
);

if(!contracts){
console.error('Could not load contracts from deployments.')
return
}
for (const key of Object.keys(contracts)) {
db.deployments[key] = contracts[key];
// TODO ABIS
Expand Down