Skip to content

Commit db2dba1

Browse files
committed
Improve error handling in generator
- Use two-value form for type assertion to avoid panic - Use %q for consistent string formatting in error messages
1 parent fc5e7fe commit db2dba1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

rules/models/generator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func main() {
109109

110110
model := findShape(shapes, shapeName)
111111
if model == nil {
112-
fmt.Printf("Shape `%s` not found, skipping\n", shapeName)
112+
fmt.Printf("Shape %q not found, skipping\n", shapeName)
113113
continue
114114
}
115115

rules/models/generator/rule.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ func fetchStrings(model map[string]interface{}, key string) []string {
9393
case []interface{}:
9494
ret := make([]string, len(v))
9595
for i, item := range v {
96-
ret[i] = item.(string)
96+
str, ok := item.(string)
97+
if !ok {
98+
return []string{}
99+
}
100+
ret[i] = str
97101
}
98102
return ret
99103
case []string:

0 commit comments

Comments
 (0)