Skip to content

Commit fdb91ef

Browse files
committed
TDP-1887 Catch exceptions during installation so that registration can run during Composer install.
1 parent 7ff6fe9 commit fdb91ef

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/FeatureToggleClientProvider.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace PartechGSS\Laravel\FeatureToggle;
44

5+
use Exception;
56
use PartechGSS\Laravel\FeatureToggle\Contracts\FeatureToggleClient;
67
use PartechGSS\Laravel\FeatureToggle\Lib\SplitIOFeatureToggleClient;
78
use Illuminate\Http\Request;
9+
use Illuminate\Support\Facades\Log;
810
use Illuminate\Support\ServiceProvider;
911
use SplitIO\Sdk;
1012
use SplitIO\Sdk\Factory\SplitFactoryInterface;
@@ -24,11 +26,15 @@ public function register()
2426

2527
$this->app->singleton(FeatureToggleClient::class, function($app) {
2628
if (config('feature-toggle')) {
27-
if (config('feature-toggle.provider') === 'splitio') {
29+
try {
30+
// This code fails when when the $HOME/split.yaml file
31+
// is missing, most notable when run from composer.
32+
// Just log, then ignore it.
2833
return new SplitIOFeatureToggleClient(static::getSplitIOFactory());
34+
} catch (Exception $e) {
35+
Log::warning("Unable to initialize Split.IO: ({$e->getMessage()}). All features will default to control treatments.");
36+
return;
2937
}
30-
31-
throw new \Exception("Unrecognized feature toggle provider " . config('feature-toggle.provider'));
3238
}
3339
});
3440
}

0 commit comments

Comments
 (0)