@@ -9,7 +9,8 @@ use std::path::PathBuf;
99use std:: sync:: Arc ;
1010
1111use crate :: keypair:: { get_keypair_path, get_payer} ;
12- use crate :: config:: TapeConfig ;
12+ use crate :: config:: { TapeConfig , TapeConfigError } ;
13+ use crate :: log;
1314
1415#[ derive( Parser ) ]
1516#[ command(
@@ -239,7 +240,68 @@ pub struct Context {
239240}
240241
241242impl Context {
242- pub fn try_build ( _cli : & Cli , config : & TapeConfig ) -> Result < Self > {
243+ pub fn try_build ( cli : & Cli ) -> Result < Self > {
244+
245+ // loading up configs
246+ let config = match TapeConfig :: load ( & cli. config ) {
247+ Ok ( config) => config,
248+ Err ( e) => match e {
249+ TapeConfigError :: ConfigFileNotFound => {
250+ log:: print_info ( "tape.toml not found, creating default configuration..." ) ;
251+ match TapeConfig :: create_default ( ) {
252+ Ok ( config) => {
253+ log:: print_info ( "✓ Default configuration created successfully" ) ;
254+ config
255+ } ,
256+ Err ( creation_error) => {
257+ log:: print_error ( & format ! ( "{}" , creation_error) ) ;
258+ std:: process:: exit ( 1 ) ;
259+ }
260+ }
261+ } ,
262+
263+ TapeConfigError :: CustomConfigFileNotFound ( path) => {
264+ // This happens when user explicitly provided a path that doesn't exist
265+ log:: print_error ( & format ! ( "Custom config file not found: {}" , path) ) ;
266+ log:: print_info ( "Please check the path and try again." ) ;
267+ std:: process:: exit ( 1 ) ;
268+ } ,
269+
270+ TapeConfigError :: InvalidUrl ( msg) => {
271+ log:: print_error ( & format ! ( "URL Configuration Error: {}" , msg) ) ;
272+ log:: print_info ( "Please fix the URL in your tape.toml file and try again." ) ;
273+ std:: process:: exit ( 1 ) ;
274+ } ,
275+
276+ TapeConfigError :: KeypairNotFound ( path) => {
277+ log:: print_error ( & format ! ( "Keypair not found at path: {}" , path) ) ;
278+ log:: print_info ( "Please ensure the keypair file exists at the specified path in tape.toml" ) ;
279+ std:: process:: exit ( 1 ) ;
280+ } ,
281+
282+ TapeConfigError :: FileReadError ( io_err) => {
283+ log:: print_error ( & format ! ( "Could not read config file: {}" , io_err) ) ;
284+ std:: process:: exit ( 1 ) ;
285+ } ,
286+
287+ TapeConfigError :: ParseError ( parse_err) => {
288+ log:: print_error ( & format ! ( "Invalid tape.toml format: {}" , parse_err) ) ;
289+ log:: print_info ( "Please check your tape.toml file syntax." ) ;
290+ std:: process:: exit ( 1 ) ;
291+ } ,
292+
293+ TapeConfigError :: HomeDirectoryNotFound => {
294+ log:: print_error ( "Could not determine home directory" ) ;
295+ std:: process:: exit ( 1 ) ;
296+ } ,
297+
298+ TapeConfigError :: DefaultConfigCreationFailed ( msg) => {
299+ log:: print_error ( & format ! ( "Failed to create default config: {}" , msg) ) ;
300+ std:: process:: exit ( 1 ) ;
301+ } ,
302+ }
303+ } ;
304+
243305 let rpc_url = config. solana . rpc_url . to_string ( ) ;
244306 let commitment_level = config. solana . commitment . to_commitment_config ( ) ;
245307 let rpc = Arc :: new (
0 commit comments