Why this matters
Prevents crashes from malformed URLs and enables clear error reporting.
Use try/catch (or Uri.tryParse with validation) around Uri.parse to guard against FormatException and invalid inputs.
Prevents crashes from malformed URLs and enables clear error reporting.
Side-by-side examples engineers can pattern-match during review.
final uri = Uri.parse(link); // may throwfinal uri = Uri.tryParse(link);
if (uri == null || !uri.hasScheme) {
logger.warning('Invalid URL', {'link': link});
return;
}
// safe to use uriUri.parse(input)final u = Uri.tryParse(input); if (u != null) open(u);From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.