When an error occurs in a nested Configuration, there is no context of where it came from.
For example, consider the following program:
import 'dart:io';
import 'package:safe_config/safe_config.dart';
class AppConfig extends Configuration {
AppConfig(String fileName) : super.fromFile(File(fileName));
String name;
String host;
ServerConfig master;
ServerConfig slave;
}
class ServerConfig extends Configuration {
String host;
int port;
}
void main(List<String> args) {
try {
final config = AppConfig(args[0]);
print('success');
} on ConfigurationException catch (e) {
print(e);
}
}
And the following invalid configuration file (it is missing the "host" for the "slave"):
name: "Missing host example"
host: local.example.com
master:
host: master.example.com
port: 443
slave:
# host: slave.example.com
port: 443
It prints out:
Invalid configuration data for 'AppConfig'. Missing required values: 'host'
But there is no indication of where exactly it was missing from. Is it the top level one, the one nested inside "master" or nested inside "slave"?
This makes finding and fixing errors in large/complex configuration files very difficult. Especially for users of the application, who don't have access to the source code and might not read any documentation about the expected configuration format.
It would be better if the exception said something like "Missing required value: slave:host". It would even be better if it could indicate the line number where the error occurred.