File tree Expand file tree Collapse file tree 3 files changed +18
-20
lines changed Expand file tree Collapse file tree 3 files changed +18
-20
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @graphprotocol/graph-cli ' : patch
3+ ---
4+
5+ Improve ABI file path validation
Original file line number Diff line number Diff line change @@ -623,47 +623,34 @@ async function processInitForm(
623623 type : 'input' ,
624624 name : 'abi' ,
625625 message : 'ABI file (path)' ,
626- initial : initAbi ,
626+ initial : initAbiPath ,
627627 skip : ( ) =>
628628 ! protocolInstance . hasABIs ( ) ||
629629 initFromExample !== undefined ||
630630 abiFromEtherscan !== undefined ||
631- isSubstreams ||
632- ! ! initAbiPath ,
631+ isSubstreams ,
633632 validate : async ( value : string ) => {
634633 if ( initFromExample || abiFromEtherscan || ! protocolInstance . hasABIs ( ) ) {
635634 return true ;
636635 }
637636
638637 const ABI = protocolInstance . getABI ( ) ;
639- if ( initAbiPath ) {
640- try {
641- loadAbiFromFile ( ABI , initAbiPath ) ;
642- return true ;
643- } catch ( e ) {
644- this . error ( e . message ) ;
645- }
646- }
638+ if ( initAbiPath ) value = initAbiPath ;
647639
648640 try {
649641 loadAbiFromFile ( ABI , value ) ;
650642 return true ;
651643 } catch ( e ) {
652- this . error ( e . message ) ;
644+ return e . message ;
653645 }
654646 } ,
655647 result : async ( value : string ) => {
656648 if ( initFromExample || abiFromEtherscan || ! protocolInstance . hasABIs ( ) ) {
657649 return null ;
658650 }
651+
659652 const ABI = protocolInstance . getABI ( ) ;
660- if ( initAbiPath ) {
661- try {
662- return loadAbiFromFile ( ABI , initAbiPath ) ;
663- } catch ( e ) {
664- return e . message ;
665- }
666- }
653+ if ( initAbiPath ) value = initAbiPath ;
667654
668655 try {
669656 return loadAbiFromFile ( ABI , value ) ;
Original file line number Diff line number Diff line change @@ -141,7 +141,13 @@ export default class ABI {
141141 }
142142
143143 static load ( name : string , file : string ) {
144- const data = JSON . parse ( fs . readFileSync ( file ) . toString ( ) ) ;
144+ let data ;
145+ try {
146+ data = JSON . parse ( fs . readFileSync ( file ) . toString ( ) ) ;
147+ } catch ( e ) {
148+ throw Error ( `Could not parse ABI: ${ e } ` ) ;
149+ }
150+
145151 const abi = ABI . normalized ( data ) ;
146152
147153 if ( abi === null || abi === undefined ) {
You can’t perform that action at this time.
0 commit comments