@@ -108,26 +108,52 @@ def finish_collection(self, success=False):
108108
109109 def _set_activity (self ):
110110 """Set the activity that convert2rhel is going to perform"""
111- self .activity = tool_opts .activity
111+ try :
112+ self .activity = tool_opts .activity
113+ if not self .activity :
114+ raise ValueError ("Activity is not set in tool_opts" )
115+ except Exception as e :
116+ print (f"Error setting activity: { e } " )
112117
113118 def _set_pkg_object (self ):
114119 """Set pkg_object which is used to get information about installed Convert2RHEL"""
115- # the index position is there because get_installed_pkg_objects return list, which is filtered and
116- # should contain just one item
117- self ._pkg_object = pkghandler .get_installed_pkg_objects (name = "convert2rhel" )[0 ]
120+ try :
121+ pkg_objects = pkghandler .get_installed_pkg_objects (name = "convert2rhel" )
122+ if not pkg_objects :
123+ raise ValueError ("No installed package objects found for convert2rhel" )
124+ self ._pkg_object = pkg_objects [0 ]
125+ except Exception as e :
126+ print (f"Error setting pkg_object: { e } " )
118127
119128 def _set_executed (self ):
120129 """Set how was Convert2RHEL executed"""
121- self .executed = " " .join (utils .hide_secrets (args = sys .argv ))
130+ try :
131+ self .executed = " " .join (utils .hide_secrets (args = sys .argv ))
132+ if not self .executed :
133+ raise ValueError ("Executed command is not set" )
134+ except Exception as e :
135+ print (f"Error setting executed: { e } " )
122136
123137 def _set_nevra (self ):
124138 """Set NEVRA of installed Convert2RHEL"""
125- self .nevra = pkghandler .get_pkg_nevra (self ._pkg_object , include_zero_epoch = True )
139+ try :
140+ self .nevra = pkghandler .get_pkg_nevra (self ._pkg_object , include_zero_epoch = True )
141+ if not self .nevra :
142+ raise ValueError ("NEVRA is not set" )
143+ except Exception as e :
144+ print (f"Error setting nevra: { e } " )
126145
127146 def _set_signature (self ):
128147 """Set signature of installed Convert2RHEL"""
129- package = pkghandler .get_installed_pkg_information (str (self ._pkg_object ))[0 ]
130- self .signature = package .signature
148+ try :
149+ package_info = pkghandler .get_installed_pkg_information (str (self ._pkg_object ))
150+ if not package_info :
151+ raise ValueError ("No package information found for convert2rhel" )
152+ self .signature = package_info [0 ].signature
153+ if not self .signature :
154+ raise ValueError ("Signature is not set" )
155+ except Exception as e :
156+ print (f"Error setting signature: { e } " )
131157
132158 def _set_started (self ):
133159 """Set start time of activity"""
0 commit comments