File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
pkg/analysis/helpers/inspector Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -16,12 +16,14 @@ limitations under the License.
16
16
package inspector
17
17
18
18
import (
19
+ "fmt"
19
20
"go/ast"
20
21
"go/token"
21
22
22
23
astinspector "golang.org/x/tools/go/ast/inspector"
23
24
"sigs.k8s.io/kube-api-linter/pkg/analysis/helpers/extractjsontags"
24
25
"sigs.k8s.io/kube-api-linter/pkg/analysis/helpers/markers"
26
+ "sigs.k8s.io/kube-api-linter/pkg/analysis/utils"
25
27
)
26
28
27
29
// Inspector is an interface that allows for the inspection of fields in structs.
@@ -103,6 +105,14 @@ func (i *inspector) InspectFields(inspectField func(field *ast.Field, stack []as
103
105
return false
104
106
}
105
107
108
+ defer func () {
109
+ if r := recover (); r != nil {
110
+ // If the inspectField function panics, we recover and log information that will help identify the issue.
111
+ debug := printDebugInfo (field )
112
+ panic (fmt .Sprintf ("%s %v" , debug , r )) // Re-panic to propagate the error.
113
+ }
114
+ }()
115
+
106
116
inspectField (field , stack , tagInfo , i .markers )
107
117
108
118
return true
@@ -152,3 +162,13 @@ func isItemsType(structType *ast.StructType) bool {
152
162
153
163
return true
154
164
}
165
+
166
+ // printDebugInfo prints debug information about the field that caused a panic during inspection.
167
+ // This function is designed to allow us to help identify which fields are causing issues during inspection.
168
+ func printDebugInfo (field * ast.Field ) string {
169
+ var debug string
170
+
171
+ debug += fmt .Sprintf ("Panic observed while inspecting field: %v (type: %v)\n " , utils .FieldName (field ), field .Type )
172
+
173
+ return debug
174
+ }
You can’t perform that action at this time.
0 commit comments