requireInt method
Requires a valid integer environment variable identified by key.
Appends description to the error message if provided.
Throws BloomEnvironmentException if the variable is missing, empty, or cannot be parsed as an integer.
Implementation
int requireInt(String key, {String? description}) {
final val = BloomEnv.getOrNull(key)?.trim();
if (val == null || val.isEmpty) {
final desc = description != null ? ' ($description)' : '';
final err = 'Missing required integer environment variable "$key"$desc.';
_validationErrors.add(err);
throw BloomEnvironmentException(err, errors: [err]);
}
final parsed = int.tryParse(val);
if (parsed == null) {
final err = 'Environment variable "$key" is not a valid integer: "$val".';
_validationErrors.add(err);
throw BloomEnvironmentException(err, errors: [err]);
}
return parsed;
}