requireInt method
Reads a required integer environment variable.
Retrieves key from BloomEnv and parses it with int.tryParse.
Throws BloomEnvironmentException and records an error in validationErrors
if the key is missing, empty, or cannot be parsed as an integer.
late final int maxRetries = requireInt('MAX_RETRIES');
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;
}