[startup_context] fail fast if /svc is not provided
Causes the StartupContext to fail fast if /svc is not
provided at startup instead of failing in a hard to
debug way when users try to connect via the incoming
object's connectToService method.
Change-Id: Ibc5634195152ca950f5054d714586abd77c214f2
diff --git a/public/dart/fuchsia_logger/lib/src/internal/_fuchsia_log_writer.dart b/public/dart/fuchsia_logger/lib/src/internal/_fuchsia_log_writer.dart
index d3c94ce..db33950 100644
--- a/public/dart/fuchsia_logger/lib/src/internal/_fuchsia_log_writer.dart
+++ b/public/dart/fuchsia_logger/lib/src/internal/_fuchsia_log_writer.dart
@@ -38,6 +38,9 @@
proxy.connect(socketPair.second).then((_) {
_socket = socketPair.first;
startListening(onMessage);
+ }).catchError((e) {
+ print('[WARN] Unable to get socket from system logger');
+ throw e;
});
}
diff --git a/public/dart/fuchsia_services/lib/src/internal/_startup_context_impl.dart b/public/dart/fuchsia_services/lib/src/internal/_startup_context_impl.dart
index f24a68f..cce544e 100644
--- a/public/dart/fuchsia_services/lib/src/internal/_startup_context_impl.dart
+++ b/public/dart/fuchsia_services/lib/src/internal/_startup_context_impl.dart
@@ -53,7 +53,14 @@
/// of instantiating one on their own as it will bind and connect to all the
/// underlying services for them.
factory StartupContextImpl.fromStartupInfo() {
- if (Directory(_serviceRootPath).existsSync()) {
+ if (Platform.isFuchsia) {
+ if (!Directory(_serviceRootPath).existsSync()) {
+ final componentName = Platform.script?.pathSegments
+ ?.lastWhere((_) => true, orElse: () => '???');
+ throw Exception(
+ 'Attempting to launch component [$componentName] without a valid /svc directory. '
+ 'This is an indication that the system is not in a valid state.');
+ }
final channel = Channel.fromFile(_serviceRootPath);
final directory = fidl_io.DirectoryProxy()
..ctrl.bind(InterfaceHandle<fidl_io.Directory>(channel));