@@ -594,6 +594,17 @@ async function processInitForm(
594594      message : `IPFS node to use for fetching subgraph manifest` , 
595595      initial : ipfsUrl , 
596596      skip : ( )  =>  ! isComposedSubgraph , 
597+       validate : value  =>  { 
598+         if  ( ! value )  { 
599+           return  'IPFS node URL cannot be empty' ; 
600+         } 
601+         try  { 
602+           new  URL ( value ) ; 
603+           return  true ; 
604+         }  catch  { 
605+           return  'Please enter a valid URL' ; 
606+         } 
607+       } , 
597608      result : value  =>  { 
598609        ipfsNode  =  value ; 
599610        initDebugger . extend ( 'processInitForm' ) ( 'ipfs: %O' ,  value ) ; 
@@ -615,9 +626,6 @@ async function processInitForm(
615626      initial : initContract , 
616627      validate : async  ( value : string ) : Promise < string  |  boolean >  =>  { 
617628        if  ( isComposedSubgraph )  { 
618-           if  ( ! ipfsNode )  { 
619-             return  true ; 
620-           } 
621629          const  ipfs  =  createIpfsClient ( ipfsNode ) ; 
622630          const  {  valid,  error }  =  await  validateSubgraphNetworkMatch ( ipfs ,  value ,  network . id ) ; 
623631          if  ( ! valid )  { 
@@ -834,22 +842,6 @@ async function processInitForm(
834842
835843    await  promptManager . executeInteractive ( ) ; 
836844
837-     // Validate network matches if loading from IPFS 
838-     if  ( ipfsNode  &&  source ?. startsWith ( 'Qm' ) )  { 
839-       const  ipfs  =  createIpfsClient ( ipfsNode ) ; 
840-       try  { 
841-         const  {  valid,  error }  =  await  validateSubgraphNetworkMatch ( ipfs ,  source ! ,  network . id ) ; 
842-         if  ( ! valid )  { 
843-           throw  new  Error ( error  ||  'Invalid subgraph network match' ) ; 
844-         } 
845-       }  catch  ( e )  { 
846-         if  ( e  instanceof  Error )  { 
847-           print . error ( `Failed to validate subgraph network: ${ e ?. message }  ) ; 
848-         } 
849-         throw  e ; 
850-       } 
851-     } 
852- 
853845    return  { 
854846      abi : ( abiFromApi  ||  abiFromFile ) ! , 
855847      protocolInstance, 
@@ -1207,10 +1199,19 @@ async function initSubgraphFromContract(
12071199        } , 
12081200      } ) ; 
12091201
1202+       // Validate network match first 
1203+       const  {  valid,  error }  =  await  validateSubgraphNetworkMatch ( ipfsClient ,  source ,  network ) ; 
1204+       if  ( ! valid )  { 
1205+         throw  new  Error ( error  ||  'Invalid subgraph network match' ) ; 
1206+       } 
1207+ 
12101208      const  schemaString  =  await  loadSubgraphSchemaFromIPFS ( ipfsClient ,  source ) ; 
12111209      const  schema  =  await  Schema . loadFromString ( schemaString ) ; 
12121210      entities  =  schema . getEntityNames ( ) ; 
12131211    }  catch  ( e )  { 
1212+       if  ( e  instanceof  Error )  { 
1213+         print . error ( `Failed to validate subgraph: ${ e ?. message }  ) ; 
1214+       } 
12141215      this . error ( `Failed to load and parse subgraph schema: ${ e . message }  ,  {  exit : 1  } ) ; 
12151216    } 
12161217  } 
0 commit comments