Skip to content

Commit faba476

Browse files
committed
return an error if a field tag is missing
1 parent 9633775 commit faba476

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

cmd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ func main() {
9191
// write the diff matrix between the enpointslice and the ss matrix to file
9292
err = os.WriteFile(filepath.Join(destDir, "matrix-diff-ss"), []byte(diff), 0644)
9393
if err != nil {
94-
panic(fmt.Sprintf("Error writing the diff matrix file :%v", err))
94+
panic(fmt.Sprintf("Error writing the diff matrix file: %v", err))
9595
}
9696
}

commatrix/generate.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ func writeMatrixToFile(matrix types.ComMatrix, fileName, format string, printFn
168168

169169
// GenerateMatrixDiff generates the diff between mat1 to mat2.
170170
func GenerateMatrixDiff(mat1 types.ComMatrix, mat2 types.ComMatrix) (string, error) {
171-
colNames := getComMatrixHeadersByFormat(types.FormatCSV)
172-
if colNames == "" {
173-
return "", fmt.Errorf("error getting commatrix CSV tags")
171+
colNames, err := getComMatrixHeadersByFormat(types.FormatCSV)
172+
if err != nil {
173+
return "", fmt.Errorf("error getting commatrix CSV tags: %v", err)
174174
}
175175

176176
diff := colNames + "\n"
@@ -201,19 +201,20 @@ func GenerateMatrixDiff(mat1 types.ComMatrix, mat2 types.ComMatrix) (string, err
201201
return diff, nil
202202
}
203203

204-
func getComMatrixHeadersByFormat(format string) string {
204+
func getComMatrixHeadersByFormat(format string) (string, error) {
205205
typ := reflect.TypeOf(types.ComDetails{})
206206

207207
var tagsList []string
208208
for i := 0; i < typ.NumField(); i++ {
209209
field := typ.Field(i)
210210
tag := field.Tag.Get(format)
211-
if tag != "" {
212-
tagsList = append(tagsList, tag)
211+
if tag == "" {
212+
return "", fmt.Errorf("field %v has not tag of format %s", field, format)
213213
}
214+
tagsList = append(tagsList, tag)
214215
}
215216

216-
return strings.Join(tagsList, ",")
217+
return strings.Join(tagsList, ","), nil
217218
}
218219

219220
func separateMatrixByRole(matrix types.ComMatrix) (types.ComMatrix, types.ComMatrix) {

0 commit comments

Comments
 (0)