@@ -37,35 +37,49 @@ pub use http_client::ProfileHTTPClient;
3737pub const DEFAULT_SCHEMA_DIR : & str = "/usr/share/agama/schema" ;
3838pub const DEFAULT_JSONNET_DIR : & str = "/usr/share/agama/jsonnet" ;
3939
40+ #[ derive( thiserror:: Error , Debug ) ]
41+ pub enum AutoyastError {
42+ #[ error( "I/O error: {0}" ) ]
43+ IO ( #[ from] std:: io:: Error ) ,
44+ #[ error( "Failed to run the agama-autoyast script: {0}" ) ]
45+ Execute ( #[ source] std:: io:: Error ) ,
46+ #[ error( "Failed to convert the AutoYaST profile: {0}" ) ]
47+ Evaluation ( String ) ,
48+ #[ error( "Unsupported AutoYaST format at {0}" ) ]
49+ UnsupportedFormat ( Url ) ,
50+ }
51+
4052/// Downloads and converts autoyast profile.
4153pub struct AutoyastProfileImporter {
4254 pub content : String ,
4355}
4456
4557impl AutoyastProfileImporter {
46- pub async fn read ( url : & Url ) -> anyhow :: Result < Self > {
58+ pub async fn read ( url : & Url ) -> Result < Self , AutoyastError > {
4759 let path = url. path ( ) ;
4860 if !path. ends_with ( ".xml" ) && !path. ends_with ( ".erb" ) && !path. ends_with ( '/' ) {
49- let msg = format ! ( "Unsupported AutoYaST format at {}" , url) ;
50- return Err ( anyhow:: Error :: msg ( msg) ) ;
61+ return Err ( AutoyastError :: UnsupportedFormat ( url. clone ( ) ) ) ;
5162 }
5263
5364 const TMP_DIR_PREFIX : & str = "autoyast" ;
5465 const AUTOINST_JSON : & str = "autoinst.json" ;
5566
5667 let tmp_dir = TempDir :: with_prefix ( TMP_DIR_PREFIX ) ?;
57- tokio:: process:: Command :: new ( "agama-autoyast" )
68+ let result = tokio:: process:: Command :: new ( "agama-autoyast" )
5869 . env ( "YAST_SKIP_PROFILE_FETCH_ERROR" , "1" )
5970 . args ( [ url. as_str ( ) , & tmp_dir. path ( ) . to_string_lossy ( ) ] )
60- . status ( )
71+ . output ( )
6172 . await
62- . context ( "Failed to run agama-autoyast" ) ?;
73+ . map_err ( AutoyastError :: Execute ) ?;
74+
75+ if !result. status . success ( ) {
76+ return Err ( AutoyastError :: Evaluation (
77+ String :: from_utf8_lossy ( & result. stderr ) . to_string ( ) ,
78+ ) ) ;
79+ }
6380
6481 let autoinst_json = tmp_dir. path ( ) . join ( AUTOINST_JSON ) ;
65- let content = fs:: read_to_string ( & autoinst_json) . context ( format ! (
66- "agama-autoyast did not produce {:?}" ,
67- autoinst_json
68- ) ) ?;
82+ let content = fs:: read_to_string ( & autoinst_json) ?;
6983 Ok ( Self { content } )
7084 }
7185}
0 commit comments