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(
623
623
type : 'input' ,
624
624
name : 'abi' ,
625
625
message : 'ABI file (path)' ,
626
- initial : initAbi ,
626
+ initial : initAbiPath ,
627
627
skip : ( ) =>
628
628
! protocolInstance . hasABIs ( ) ||
629
629
initFromExample !== undefined ||
630
630
abiFromEtherscan !== undefined ||
631
- isSubstreams ||
632
- ! ! initAbiPath ,
631
+ isSubstreams ,
633
632
validate : async ( value : string ) => {
634
633
if ( initFromExample || abiFromEtherscan || ! protocolInstance . hasABIs ( ) ) {
635
634
return true ;
636
635
}
637
636
638
637
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 ;
647
639
648
640
try {
649
641
loadAbiFromFile ( ABI , value ) ;
650
642
return true ;
651
643
} catch ( e ) {
652
- this . error ( e . message ) ;
644
+ return e . message ;
653
645
}
654
646
} ,
655
647
result : async ( value : string ) => {
656
648
if ( initFromExample || abiFromEtherscan || ! protocolInstance . hasABIs ( ) ) {
657
649
return null ;
658
650
}
651
+
659
652
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 ;
667
654
668
655
try {
669
656
return loadAbiFromFile ( ABI , value ) ;
Original file line number Diff line number Diff line change @@ -141,7 +141,13 @@ export default class ABI {
141
141
}
142
142
143
143
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
+
145
151
const abi = ABI . normalized ( data ) ;
146
152
147
153
if ( abi === null || abi === undefined ) {
You can’t perform that action at this time.
0 commit comments