@@ -25,6 +25,13 @@ func DumpCore(ctx context.Context, khCfg *config.KubehoundConfig, upload bool) (
25
25
l := log .Logger (ctx )
26
26
27
27
clusterName , err := config .GetClusterName (ctx )
28
+ defer func () {
29
+ if err != nil {
30
+ errMsg := fmt .Errorf ("fatal error: %w" , err )
31
+ l .Error ("Error occurred" , log .ErrorField (errMsg ))
32
+ _ = events .PushEvent (ctx , events .DumpFailed , fmt .Sprintf ("%s" , errMsg ))
33
+ }
34
+ }()
28
35
if err != nil {
29
36
return "" , fmt .Errorf ("collector cluster info: %w" , err )
30
37
}
@@ -36,6 +43,7 @@ func DumpCore(ctx context.Context, khCfg *config.KubehoundConfig, upload bool) (
36
43
37
44
span , ctx := span .SpanRunFromContext (ctx , span .DumperLaunch )
38
45
span .SetTag (ext .ManualKeep , true )
46
+ l = log .Logger (ctx )
39
47
defer func () {
40
48
span .Finish (tracer .WithError (err ))
41
49
}()
@@ -53,12 +61,16 @@ func DumpCore(ctx context.Context, khCfg *config.KubehoundConfig, upload bool) (
53
61
if upload {
54
62
// Clean up the temporary directory when done
55
63
defer func () {
56
- err = os .RemoveAll (khCfg .Collector .File .Directory )
64
+ // This error is scope to the defer and not be handled by the other defer function
65
+ err := os .RemoveAll (khCfg .Collector .File .Directory )
57
66
if err != nil {
67
+ errMsg := fmt .Errorf ("Failed to remove temporary directory: %w" , err )
58
68
l .Error ("Failed to remove temporary directory" , log .ErrorField (err ))
69
+ _ = events .PushEvent (ctx , events .DumpFailed , fmt .Sprintf ("%s" , errMsg ))
59
70
}
60
71
}()
61
- puller , err := blob .NewBlobStorage (khCfg , khCfg .Ingestor .Blob )
72
+ var puller * blob.BlobStore
73
+ puller , err = blob .NewBlobStorage (khCfg , khCfg .Ingestor .Blob )
62
74
if err != nil {
63
75
return "" , err
64
76
}
0 commit comments