Skip to content

Commit 4a1729d

Browse files
committed
Merge branch 'JuPrgn-patch-1' into dev
2 parents fdc2fab + b69e510 commit 4a1729d

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

kibot/bom/units.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,18 @@ def comp_match(component, ref_prefix, ref=None, relax_severity=False, stronger=F
219219
# This is used to parse things like "1/8 W", but we get "1/8" here
220220
result = re.match(r'(\d+)\/(\d+)', component)
221221
if result:
222-
val = int(result.group(1))/int(result.group(2))
223-
val, pow = get_prefix(val, '')
224-
parsed = ParsedValue(val, pow, get_unit('', ref_prefix))
225-
# Cache the result
226-
parser_cache[original+ref_prefix] = parsed
227-
return parsed
222+
# Avoid division by zero
223+
if int(result.group(2)) != 0:
224+
val = int(result.group(1))/int(result.group(2))
225+
val, pow = get_prefix(val, '')
226+
parsed = ParsedValue(val, pow, get_unit('', ref_prefix))
227+
# Cache the result
228+
parser_cache[original+ref_prefix] = parsed
229+
return parsed
230+
else:
231+
result = None
232+
log_func_warn(W_EXTRAINVAL+f"Malformed value: `{original}` (avoid adding extra information in the value)")
233+
228234
if not result:
229235
# Failed with the regex, try with the parser
230236
result = parse(ref_prefix[0]+' '+with_commas, with_extra=True, stronger=stronger)

0 commit comments

Comments
 (0)