@@ -73,18 +73,16 @@ func checkSize(buildProperties properties.Map, verbose bool, warningsLevel strin
73
73
if err != nil {
74
74
return err
75
75
}
76
- maxDataSize := - 1
77
76
77
+ maxDataSize := - 1
78
78
if maxDataSizeString != "" {
79
79
maxDataSize , err = strconv .Atoi (maxDataSizeString )
80
80
if err != nil {
81
81
return err
82
82
}
83
83
}
84
84
85
- textSize , dataSize , eepromSize := - 1 , - 1 , - 1
86
-
87
- err = execSizeReceipe (properties , logger , & textSize , & dataSize , & eepromSize )
85
+ textSize , dataSize , _ , err := execSizeReceipe (properties , logger )
88
86
if err != nil {
89
87
logger .Println (constants .LOG_LEVEL_WARN , constants .MSG_SIZER_ERROR_NO_RULE )
90
88
return nil
@@ -122,12 +120,11 @@ func checkSize(buildProperties properties.Map, verbose bool, warningsLevel strin
122
120
return nil
123
121
}
124
122
125
- func execSizeReceipe (properties properties.Map , logger i18n.Logger , textSize * int , dataSize * int , eepromSize * int ) error {
126
-
123
+ func execSizeReceipe (properties properties.Map , logger i18n.Logger ) (textSize int , dataSize int , eepromSize int , resErr error ) {
127
124
out , err := builder_utils .ExecRecipe (properties , constants .RECIPE_SIZE_PATTERN , false , false , false , logger )
128
-
129
125
if err != nil {
130
- return errors .New ("" )
126
+ resErr = errors .New ("Error while determining sketch size: " + err .Error ())
127
+ return
131
128
}
132
129
133
130
// force multiline match prepending "(?m)" to the actual regexp
@@ -136,46 +133,56 @@ func execSizeReceipe(properties properties.Map, logger i18n.Logger, textSize *in
136
133
if len (properties [constants .RECIPE_SIZE_REGEXP ]) > 0 {
137
134
textRegexp , err := regexp .Compile ("(?m)" + properties [constants .RECIPE_SIZE_REGEXP ])
138
135
if err != nil {
139
- return errors .New ("" )
136
+ resErr = errors .New ("Invalid size regexp: " + err .Error ())
137
+ return
140
138
}
141
139
result := textRegexp .FindAllSubmatch (out , - 1 )
142
140
for _ , b := range result {
143
141
for _ , c := range b {
144
- res , _ := strconv .Atoi (string (c ))
145
- * textSize += res
142
+ if res , err := strconv .Atoi (string (c )); err == nil {
143
+ textSize += res
144
+ }
146
145
}
147
146
}
148
147
} else {
149
- return errors .New ("" )
148
+ resErr = errors .New ("Missing size regexp" )
149
+ return
150
150
}
151
151
152
152
if len (properties [constants .RECIPE_SIZE_REGEXP_DATA ]) > 0 {
153
153
dataRegexp , err := regexp .Compile ("(?m)" + properties [constants .RECIPE_SIZE_REGEXP_DATA ])
154
154
if err != nil {
155
- return errors .New ("" )
155
+ resErr = errors .New ("Invalid data size regexp: " + err .Error ())
156
+ return
156
157
}
157
158
result := dataRegexp .FindAllSubmatch (out , - 1 )
158
159
for _ , b := range result {
159
160
for _ , c := range b {
160
- res , _ := strconv .Atoi (string (c ))
161
- * dataSize += res
161
+ if res , err := strconv .Atoi (string (c )); err == nil {
162
+ dataSize += res
163
+ }
162
164
}
163
165
}
166
+ } else {
167
+ dataSize = - 1
164
168
}
165
169
166
170
if len (properties [constants .RECIPE_SIZE_REGEXP_EEPROM ]) > 0 {
167
171
eepromRegexp , err := regexp .Compile ("(?m)" + properties [constants .RECIPE_SIZE_REGEXP_EEPROM ])
168
172
if err != nil {
169
- return errors .New ("" )
173
+ resErr = errors .New ("Invalid eeprom size regexp: " + err .Error ())
174
+ return
170
175
}
171
176
result := eepromRegexp .FindAllSubmatch (out , - 1 )
172
177
for _ , b := range result {
173
178
for _ , c := range b {
174
- res , _ := strconv .Atoi (string (c ))
175
- * eepromSize += res
179
+ if res , err := strconv .Atoi (string (c )); err == nil {
180
+ eepromSize += res
181
+ }
176
182
}
177
183
}
184
+ } else {
185
+ eepromSize = - 1
178
186
}
179
-
180
- return nil
187
+ return
181
188
}
0 commit comments