georgeboot / laravel-echo-api-gateway

Use Laravel Echo with API Gateway Websockets. Works with Bref.sh and Laravel Vapor.
MIT License
99 stars 22 forks source link

Getting an Error installing the Package with Composer #5

Closed julianlaibach closed 3 years ago

julianlaibach commented 3 years ago

Great work, thank you! I`m getting the following Error installing the Package: Argument 1 passed to Georgeboot\LaravelEchoApiGateway\SubscriptionRepository::__construct() must be of the type array, null given, called in /var/www/html/vendor/georgeboot/laravel-echo-api-gateway/src/ServiceProvider.php on line 37

I'm not sure where the config variable is passed from.

Thank you!

georgeboot commented 3 years ago

Thanks for raising an issue!

Can you share the contents of your laravel-echo-api-gateway.php config file with me? It seems there is an issue there.

julianlaibach commented 3 years ago
<?php

return [

    'connection' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'token' => env('AWS_SESSION_TOKEN'),
        'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
    ],

    'api' => [
        'id' => env('LARAVEL_ECHO_API_GATEWAY_API_ID'),
        'stage' => env('LARAVEL_ECHO_API_GATEWAY_API_STAGE'),
    ],

    'dynamodb' => [
        'endpoint' => env('DYNAMODB_ENDPOINT'),
        'table' => env('LARAVEL_ECHO_API_GATEWAY_DYNAMODB_TABLE', 'connections'),
    ],

];

This is the Code inside the laravel-echo-api-gateway.php file... Do i have to Replace anything there? Thank you!

julianlaibach commented 3 years ago

I uncommented the following line in the ServiceProvider, now the installation via composer on my local machine works: $this->commands([ VaporHandle::class, ]);

julianlaibach commented 3 years ago

After i reinstalled the Package the Previous Issue was gone, but now i´m getting the following Error in my AWS CLI console (deployed using Laravel Vapor)

{
    "message": "Unknown event type. Please create a vapor:handle command to handle custom events.",
    "context": {
        "exception": {
            "class": "InvalidArgumentException",
            "message": "Unknown event type. Please create a vapor:handle command to handle custom events.",
            "code": 0,
            "file": "/var/task/vendor/laravel/vapor-core/src/VaporServiceProvider.php:155"
        },
        "aws_request_id": "26b6b030-8785-4fb9-9825-e8bbf7df2fa6"
    },
    "level": 400,
    "level_name": "ERROR",
    "channel": "production",
    "datetime": "2021-03-27T16:59:56.437691+00:00",
    "extra": {}
}

I than tried to debug this and created a custom Code Snippet in the console.php

Artisan::command('vapor:handle {payload}', function ($payload) {
    $this->info("Test");
});

I´m now getting the following Log Output

{
    "output": "Test\n",
    "context": {
        "command": "php /var/task/artisan vapor:handle eyJyZXF1ZXN0Q29udGV4dCI6eyJyb3V0ZUtleSI6IiRkZWZhdWx0IiwiZGlzY29ubmVjdFN0YXR1c0NvZGUiOm51bGwsIm1lc3NhZ2VJZCI6ImMyODFwZW9jbGlBQ0ZrQT0iLCJldmVudFR5cGUiOiJNRVNTQUdFIiwiZXh0ZW5kZWRSZXF1ZXN0SWQiOiJjMjgxcEhsdkZpQUZVcVE9IiwicmVxdWVzdFRpbWUiOiIyN1wvTWFyXC8yMDIxOjE4OjA5OjUyICswMDAwIiwibWVzc2FnZURpcmVjdGlvbiI6IklOIiwiZGlzY29ubmVjdFJlYXNvbiI6bnVsbCwic3RhZ2UiOiJwcm9kdWN0aW9uIiwiY29ubmVjdGVkQXQiOjE2MTY4NjcxMTQ5ODUsInJlcXVlc3RUaW1lRXBvY2giOjE2MTY4Njg1OTI4NDYsImlkZW50aXR5Ijp7ImNvZ25pdG9JZGVudGl0eVBvb2xJZCI6bnVsbCwiY29nbml0b0lkZW50aXR5SWQiOm51bGwsInByaW5jaXBhbE9yZ0lkIjpudWxsLCJjb2duaXRvQXV0aGVudGljYXRpb25UeXBlIjpudWxsLCJ1c2VyQXJuIjpudWxsLCJ1c2VyQWdlbnQiOiJNb3ppbGxhXC81LjAgKE1hY2ludG9zaDsgSW50ZWwgTWFjIE9TIFggMTFfMl8xKSBBcHBsZVdlYktpdFwvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lXC84OS4wLjQzODkuOTAgU2FmYXJpXC81MzcuMzYiLCJhY2NvdW50SWQiOm51bGwsImNhbGxlciI6bnVsbCwic291cmNlSXAiOiI4NC4xNDguNzAuMTM5IiwiYWNjZXNzS2V5IjpudWxsLCJjb2duaXRvQXV0aGVudGljYXRpb25Qcm92aWRlciI6bnVsbCwidXNlciI6bnVsbH0sInJlcXVlc3RJZCI6ImMyODFwSGx2RmlBRlVxUT0iLCJkb21haW5OYW1lIjoiM3NpZm5lZjBray5leGVjdXRlLWFwaS5ldS1jZW50cmFsLTEuYW1hem9uYXdzLmNvbSIsImNvbm5lY3Rpb25JZCI6ImMyNU91ZGJLRmlBQ0ZrQT0iLCJhcGlJZCI6IjNzaWZuZWYwa2sifSwiYm9keSI6IntcImV2ZW50XCI6XCJwaW5nXCJ9IiwiaXNCYXNlNjRFbmNvZGVkIjpmYWxzZX0= --no-interaction 2>&1",
        "aws_request_id": "5a1c14dd-edaa-44ca-af40-f34f714dbc79"
    }
}
julianlaibach commented 3 years ago

Ok so i think i maybe found the issue, on my local Machine once i move the following Code

$this->commands([
            VaporHandle::class
]);

into the boot function the command is registered properly.

georgeboot commented 3 years ago

And once it is registered properly, do you still get the lambda invocation error?

julianlaibach commented 3 years ago

Yes I deployed this morning and everything works well! I don't have any issues anymore :)

georgeboot commented 3 years ago

Awesome! So how did you resolve your initial issue

Argument 1 passed to Georgeboot\LaravelEchoApiGateway\SubscriptionRepository::__construct() must be of the type array, null given, called in /var/www/html/vendor/georgeboot/laravel-echo-api-gateway/src/ServiceProvider.php on line 37 ?

I will take a look and see why registering VaporHandle in the boot method does work, but when registering in the register method, it doesn't.

georgeboot commented 3 years ago

I just released 0.1.1 that moves the command registration to the boot method.

julianlaibach commented 3 years ago

Nice thank you! :) my initial issue was resolved due to a reinstallation... I'm not quite sure why this error appeared, i restarted the docker container removed the package and reinstalled it.. after this everything was working! Besides the vapor:handle.

mikebronner commented 3 years ago

Hi, I just tried installing fresh, no custom config file, and got the same error:

Georgeboot\LaravelEchoApiGateway\SubscriptionRepository::__construct(): Argument #1 ($config) must be of type array, null given, called in /home/forge/xxxxxxxxxx/vendor/georgeboot/laravel-echo-api-gateway/src/ServiceProvider.php on line 37

  at vendor/georgeboot/laravel-echo-api-gateway/src/SubscriptionRepository.php:15
     11▕ {
     12▕     protected DynamoDbClient $dynamoDb;
     13▕     protected string $table;
     14▕ 
  ➜  15▕     public function __construct(array $config)
     16▕     {
     17▕         $this->dynamoDb = new DynamoDbClient(array_merge($config['connection'], [
     18▕             'version' => '2012-08-10',
     19▕             'endpoint' => $config['dynamodb']['endpoint'],

This happens whenever I run:

composer require georgeboot/laravel-echo-api-gateway

@georgeboot Might be good to re-open this issue?

georgeboot commented 3 years ago

What happens when you manually create the config file, and then install the package?

mikebronner commented 3 years ago

Unfortunately that doesn't seem to help. I'm working on backtracking the bug, in the meantime, here is the full stack-trace:

[2021-03-30 18:55:21] local.ERROR: Georgeboot\LaravelEchoApiGateway\SubscriptionRepository::__construct(): Argument #1 ($config) must be of type array, null given, called in /home/forge/mike-b.totalitylms.com/vendor/georgeboot/laravel-echo-api-gateway/src/ServiceProvider.php on line 37 {"exception":"[object] (TypeError(code: 0): Georgeboot\\LaravelEchoApiGateway\\SubscriptionRepository::__construct(): Argument #1 ($config) must be of type array, null given, called in /home/forge/mike-b.totalitylms.com/vendor/georgeboot/laravel-echo-api-gateway/src/ServiceProvider.php on line 37 at /home/forge/mike-b.totalitylms.com/vendor/georgeboot/laravel-echo-api-gateway/src/SubscriptionRepository.php:15)
[stacktrace]
#0 /home/forge/mike-b.totalitylms.com/vendor/georgeboot/laravel-echo-api-gateway/src/ServiceProvider.php(37): Georgeboot\\LaravelEchoApiGateway\\SubscriptionRepository->__construct()
#1 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(829): Georgeboot\\LaravelEchoApiGateway\\ServiceProvider->Georgeboot\\LaravelEchoApiGateway\\{closure}()
#2 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\\Container\\Container->build()
#3 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\\Container\\Container->resolve()
#4 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\\Foundation\\Application->resolve()
#5 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\\Container\\Container->make()
#6 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(987): Illuminate\\Foundation\\Application->make()
#7 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(907): Illuminate\\Container\\Container->resolveClass()
#8 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(868): Illuminate\\Container\\Container->resolveDependencies()
#9 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\\Container\\Container->build()
#10 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\\Container\\Container->resolve()
#11 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\\Foundation\\Application->resolve()
#12 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\\Container\\Container->make()
#13 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(987): Illuminate\\Foundation\\Application->make()
#14 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(907): Illuminate\\Container\\Container->resolveClass()
#15 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(868): Illuminate\\Container\\Container->resolveDependencies()
#16 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\\Container\\Container->build()
#17 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\\Container\\Container->resolve()
#18 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\\Foundation\\Application->resolve()
#19 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\\Container\\Container->make()
#20 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Console/Application.php(260): Illuminate\\Foundation\\Application->make()
#21 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Console/Application.php(274): Illuminate\\Console\\Application->resolve()
#22 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php(396): Illuminate\\Console\\Application->resolveCommands()
#23 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Console/Application.php(151): Illuminate\\Support\\ServiceProvider->Illuminate\\Support\\{closure}()
#24 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Console/Application.php(74): Illuminate\\Console\\Application->bootstrap()
#25 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(330): Illuminate\\Console\\Application->__construct()
#26 /home/forge/mike-b.totalitylms.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Foundation\\Console\\Kernel->getArtisan()
#27 Command line code(1): Illuminate\\Foundation\\Console\\Kernel->handle()
#28 {main}
"} 
georgeboot commented 3 years ago

Could you please try installing the dev-master version and tell me if that one works or not?

mikebronner commented 3 years ago

@georgeboot Absolutely, brb.

Update: I did receive the same error message:

> @php artisan package:discover --ansi

   TypeError 

  Georgeboot\LaravelEchoApiGateway\SubscriptionRepository::__construct(): Argument #1 ($config) must be of type array, null given, called in /home/forge/mike-b.totalitylms.com/vendor/georgeboot/laravel-echo-api-gateway/src/ServiceProvider.php on line 25

  at vendor/georgeboot/laravel-echo-api-gateway/src/SubscriptionRepository.php:15
     11▕ {
     12▕     protected DynamoDbClient $dynamoDb;
     13▕     protected string $table;
     14▕ 
  ➜  15▕     public function __construct(array $config)
     16▕     {
     17▕         $this->dynamoDb = new DynamoDbClient(array_merge($config['connection'], [
     18▕             'version' => '2012-08-10',
     19▕             'endpoint' => $config['dynamodb']['endpoint'],
georgeboot commented 3 years ago

What PHP and Laravel version are you on? Just created a fresh Laravel 8.35.0 on PHP 8.0.1 and working perfectly out of the box. So can't really replicate.

mikebronner commented 3 years ago

Here is my system info:

The following is my require section from composer.json:

        "php": "^8.0",
        "algolia/algoliasearch-client-php": "^2.7",
        "aws/aws-sdk-php": "^3.138",
        "barryvdh/laravel-dompdf": "^0.9.0",
        "binarycabin/laravel-uuid": "^1.0",
        "bugsnag/bugsnag-laravel": "^2.21",
        "doctrine/dbal": "^2.10",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^2.0",
        "genealabs/laravel-casts": "dev-feature/upgrade-to-blade-components@dev",
        "genealabs/laravel-governor": "^0.17.6",
        "genealabs/laravel-multi-step-progressbar": "dev-master@dev",
        "genealabs/laravel-optimized-postgres": "^0.4.0",
        "genealabs/laravel-socialiter": "^0.3.3",
        "geoffreyrose/us-holidays": "dev-patch-1@dev",
        "georgeboot/laravel-echo-api-gateway": "dev-master@dev",
        "guzzlehttp/guzzle": "^7.0",
        "hellosign/hellosign-php-sdk": "^3.6",
        "hisorange/browser-detect": "^4.4",
        "kirkbushell/eloquence": "dev-patch-1@dev",
        "laravel-frontend-presets/tall": "^2.1",
        "laravel-notification-channels/twilio": "^3.0",
        "laravel/framework": "^8.0",
        "laravel/nexmo-notification-channel": "^2.5",
        "laravel/passport": "^10.1",
        "laravel/scout": "^8.4",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^3.0",
        "laravel/vapor-cli": "^1.14",
        "laravel/vapor-core": "^2.10",
        "laravel/vapor-ui": "^1.0",
        "league/csv": "^9.6",
        "livewire/livewire": "^2.4",
        "mvdnbrk/laravel-postmark-webhooks": "^1.6",
        "owen-it/laravel-auditing": "^10.0",
        "socialiteproviders/laravelpassport": "^4.0",
        "tinymce/tinymce": "^5.6",
        "toin0u/geocoder-laravel": "^4.4",
        "totality/cashier-authorizedotnet": "dev-master@dev",
        "totality/cashier-core": "dev-master@dev",
        "totality/cashier-eftbop": "dev-master@dev",
        "wildbit/swiftmailer-postmark": "^3.3"
georgeboot commented 3 years ago

Thanks. And you env variables?

mikebronner commented 3 years ago

I believe the problem is that you are binding the subscription repository and connection repository in the registration method, instead of the boot method. The config will always be empty during registration, I think?

mikebronner commented 3 years ago

I think I have a fix ... let me submit it as a PR for your review and see what you think.

mikebronner commented 3 years ago

@georgeboot See if #7 does the trick?

georgeboot commented 3 years ago

I believe the problem is that you are binding the subscription repository and connection repository in the registration method, instead of the boot method. The config will always be empty during registration, I think?

Nope. Service providers are first all registered, then they are booted. During registering, we register a way to resolve the service (we provide a closure, not an abstract implementation).

Can you please check (using Ray or a log file) if both the register and boot methods of the service provider are called before you get the error? If so, does it get past the last line of the Drivers constructor? https://github.com/georgeboot/laravel-echo-api-gateway/blob/1e642117f90e60b7eea9de388f107c29c681befd/src/Driver.php#L20-L24

mikebronner commented 3 years ago

This is really weird. I am no longer able to replicate the issue. It seems to have gone away after it successfully loaded the config data once (by implementing my hack from the PR). After that it always loads it fine, even after clearing config cache, deleting cache files, even reinstalling the package.

georgeboot commented 3 years ago

Glad that it's working at least. I'll leave this issue open until there is a more permanent fix, or no other occurrences come up.