requireString method

String requireString(
  1. String key, {
  2. String? description,
})

Requires a non-empty string environment variable identified by key.

Appends description to the error message if provided. Throws BloomEnvironmentException if the variable is missing or empty.

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;
}