requireString method
Reads a required non-empty string environment variable.
Retrieves key from BloomEnv, trimming leading and trailing whitespace.
Throws BloomEnvironmentException and records a failure in validationErrors
if the key is absent or empty.
description optionally adds human-readable context to the error message.
late final String apiKey = requireString('API_KEY', description: 'Secret API Key');
Implementation
String requireString(String key, {String? description}) {
final val = BloomEnv.getOrNull(key)?.trim();
if (val == null || val.isEmpty) {
final desc = description != null ? ' ($description)' : '';
final err = 'Missing required environment variable "$key"$desc.';
_validationErrors.add(err);
throw BloomEnvironmentException(err, errors: [err]);
}
return val;
}