Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/soft-scissors-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

Improve ABI file path validation
25 changes: 6 additions & 19 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,47 +623,34 @@
type: 'input',
name: 'abi',
message: 'ABI file (path)',
initial: initAbi,
initial: initAbiPath,
skip: () =>
!protocolInstance.hasABIs() ||
initFromExample !== undefined ||
abiFromEtherscan !== undefined ||
isSubstreams ||
!!initAbiPath,
isSubstreams,
validate: async (value: string) => {
if (initFromExample || abiFromEtherscan || !protocolInstance.hasABIs()) {
return true;
}

const ABI = protocolInstance.getABI();
if (initAbiPath) {
try {
loadAbiFromFile(ABI, initAbiPath);
return true;
} catch (e) {
this.error(e.message);
}
}
if (initAbiPath) value = initAbiPath;

try {
loadAbiFromFile(ABI, value);
return true;
} catch (e) {
this.error(e.message);
return e.message;
}
},
result: async (value: string) => {
if (initFromExample || abiFromEtherscan || !protocolInstance.hasABIs()) {
return null;
}

const ABI = protocolInstance.getABI();
if (initAbiPath) {
try {
return loadAbiFromFile(ABI, initAbiPath);
} catch (e) {
return e.message;
}
}
if (initAbiPath) value = initAbiPath;

try {
return loadAbiFromFile(ABI, value);
Expand Down Expand Up @@ -1102,7 +1089,7 @@
}

if (protocolInstance.hasContract()) {
const identifierName = protocolInstance.getContract()!.identifierName();

Check warning on line 1092 in packages/cli/src/commands/init.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion
const networkConf = await initNetworksConfig(directory, identifierName);
if (networkConf !== true) {
process.exitCode = 1;
Expand Down Expand Up @@ -1165,7 +1152,7 @@
const addContractConfirmation = addContractAnswer.toLowerCase() === 'y';

if (addContractConfirmation) {
const ProtocolContract = protocolInstance.getContract()!;

Check warning on line 1155 in packages/cli/src/commands/init.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion

let contract = '';
for (;;) {
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/protocols/ethereum/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ export default class ABI {
}

static load(name: string, file: string) {
const data = JSON.parse(fs.readFileSync(file).toString());
let data;
try {
data = JSON.parse(fs.readFileSync(file).toString());
} catch (e) {
throw Error(`Could not parse ABI: ${e}`);
}

const abi = ABI.normalized(data);

if (abi === null || abi === undefined) {
Expand Down
Loading