@@ -296,41 +296,27 @@ def get_resource_yaml(event: KubernetesResourceEvent):
296296 """
297297 resource = event .get_resource ()
298298 if not resource :
299- logging .error ("resource not found..." )
300- return
299+ raise ActionException (ErrorCodes .RESOURCE_NOT_FOUND , "Resource not found for get resource yaml." )
301300
302301 resource_kind = resource .kind
303302 namespace : str = resource .metadata .namespace
304303 name : str = resource .metadata .name
305304
306305 if resource_kind .lower () in RESOURCE_YAML_BLOCK_LIST :
307- event .add_enrichment (
308- [
309- MarkdownBlock (f"{ resource_kind } is blocked." ),
310- FileBlock (f"{ name } .yaml" , f"{ resource_kind } is blocked." .encode ()),
311- ],
312- )
313- return
306+ raise ActionException (ErrorCodes .RESOURCE_NOT_PERMITTED , f"{ resource_kind .lower ()} type is blocked for get resource yaml." )
314307
315308 try :
316309 resource_yaml = hikaru .get_yaml (resource )
317-
318310 event .add_enrichment (
319311 [
320312 MarkdownBlock (f"Your YAML file for { resource_kind } { namespace } /{ name } " ),
321313 FileBlock (f"{ name } .yaml" , resource_yaml .encode ()),
322314 ],
323315 )
324316 except KeyError :
325- logging .error (f"{ resource_kind } is not supported resource kind" )
326- except kubernetes .client .exceptions .ApiException as exc :
327- if exc .status == 404 :
328- logging .error (f"{ resource_kind .title ()} { namespace } /{ name } was not found" )
329- else :
330- logging .error (f"A following error occurred: { str (exc )} " )
331- except Exception as exc :
332- logging .error ("Unexpected error occurred!" )
333- logging .exception (exc )
317+ raise ActionException (ErrorCodes .RESOURCE_NOT_SUPPORTED , f"{ resource_kind } is not supported for get resource yaml." )
318+ except Exception as e :
319+ raise ActionException (ErrorCodes .ACTION_UNEXPECTED_ERROR , f"{ e } " )
334320
335321
336322class NamedResourcesParams (ActionParams ):
0 commit comments