Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatabaseEntriesRepository array access error with one liner fix #1164

Closed
tipjoe opened this issue Dec 29, 2021 · 3 comments · Fixed by #1165
Closed

DatabaseEntriesRepository array access error with one liner fix #1164

tipjoe opened this issue Dec 29, 2021 · 3 comments · Fixed by #1165
Labels

Comments

@tipjoe
Copy link

tipjoe commented Dec 29, 2021

  • Telescope Version: 4.6.9
  • Laravel Version: 8.69.0
  • PHP Version: 8.0.12
  • Database Driver & Version: mysqli and pdo_mysql for mysql 5.7.36-log

Description:

When telescope attempts to track entries for artisan commands, it causes this:

[2021-12-29 13:43:21] dev.ERROR: Attempt to read property "content" on array {"exception":"[object] (ErrorException(code: 0): Attempt to read property \"content\" on array at /app/vendor/laravel/telescope/src/Storage/DatabaseEntriesRepository.php:222)

At line 222, it attempts to read an object property ($entry->content), but $entry is an array so it should reference $entry['content'].

image

This is in the update method. The store method may have this issue if a collection isn't passed as the $entries arg.
Other places in this file refer to an $entry variable that is an object, so it correctly uses arrow notation.

Steps To Reproduce:

  1. Enable telescope
  2. Run an artisan command. In our case, it was a custom Command. Stack trace below shows that this bug is happening within the DatabaseEntriesRepository triggered by the artisan command before it even reaches our app code.

Current Workaround

One-line fix below. Things seem to be working elsewhere so our workaround is to disable command watching with TELESCOPE_COMMAND_WATCHER=false in a .env file.

Steps to Fix:

  1. At Storage/DatabaseEntriesRepository.php:222, use $entry['content'] instead of $entry->content.

Stack trace
[2021-12-29 13:13:23] dev.ERROR: Attempt to read property "content" on array {"exception":"[object] (ErrorException(code: 0): Attempt to read property \"content\" on array at /app/vendor/laravel/telescope/src/Storage/DatabaseEntriesRepository.php:222) [stacktrace] #0 /app/vendor/laravel/telescope/src/Storage/DatabaseEntriesRepository.php(222): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'Attempt to read...', '/app/vendor/lar...', 222) #1 /app/vendor/laravel/telescope/src/Telescope.php(661): Laravel\\Telescope\\Storage\\DatabaseEntriesRepository->update(Object(Illuminate\\Support\\Collection)) #2 [internal function]: Laravel\\Telescope\\Telescope::Laravel\\Telescope\\{closure}() #3 /app/vendor/laravel/telescope/src/Telescope.php(281): call_user_func(Object(Closure)) #4 /app/vendor/laravel/telescope/src/Telescope.php(671): Laravel\\Telescope\\Telescope::withoutRecording(Object(Closure)) #5 /app/vendor/laravel/telescope/src/ListensForStorageOpportunities.php(110): Laravel\\Telescope\\Telescope::store(Object(Laravel\\Telescope\\Storage\\DatabaseEntriesRepository)) #6 /app/vendor/laravel/telescope/src/ListensForStorageOpportunities.php(90): Laravel\\Telescope\\Telescope::storeIfDoneProcessingJob(Object(Illuminate\\Queue\\Events\\JobFailed), Object(Illuminate\\Foundation\\Application)) #7 /app/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(404): Laravel\\Telescope\\Telescope::Laravel\\Telescope\\{closure}(Object(Illuminate\\Queue\\Events\\JobFailed)) #8 /app/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(249): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('Illuminate\\\\Queu...', Array) #9 /app/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(195): Illuminate\\Events\\Dispatcher->dispatch('Illuminate\\\\Queu...') #10 /app/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(581): Illuminate\\Queue\\Jobs\\Job->fail(Object(TypeError)) #11 /app/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(527): Illuminate\\Queue\\Worker->failJob(Object(VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob), Object(TypeError)) #12 /app/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(455): Illuminate\\Queue\\Worker->markJobAsFailedIfWillExceedMaxAttempts('rabbitmq', Object(VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob), 1, Object(TypeError)) #13 /app/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(432): Illuminate\\Queue\\Worker->handleJobException('rabbitmq', Object(VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob), Object(Illuminate\\Queue\\WorkerOptions), Object(TypeError)) #14 /app/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(378): Illuminate\\Queue\\Worker->process('rabbitmq', Object(VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob), Object(Illuminate\\Queue\\WorkerOptions)) #15 /app/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(172): Illuminate\\Queue\\Worker->runJob(Object(VladimirYuldashev\\LaravelQueueRabbitMQ\\Queue\\Jobs\\RabbitMQJob), 'rabbitmq', Object(Illuminate\\Queue\\WorkerOptions)) #16 /app/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(117): Illuminate\\Queue\\Worker->daemon('rabbitmq', 'calls,jumpballN...', Object(Illuminate\\Queue\\WorkerOptions)) #17 /app/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\\Queue\\Console\\WorkCommand->runWorker('rabbitmq', 'calls,jumpballN...') #18 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle() #19 /app/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}() #20 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure)) #21 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure)) #22 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL) #23 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array) #24 /app/vendor/symfony/console/Command/Command.php(299): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle)) #25 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle)) #26 /app/vendor/symfony/console/Application.php(978): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #27 /app/vendor/symfony/console/Application.php(295): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #28 /app/vendor/symfony/console/Application.php(167): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #29 /app/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #30 /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #31 /app/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #32 {main} "}

@driesvints
Copy link
Member

At Storage/DatabaseEntriesRepository.php:222, use $entry['content'] instead of $entry->content.

I don't think this is a good solution as it's intended to be an object. Most likely, you're using array hydration instead of object hydration. Something we can do is first attempt object hydration and later on array hydration. I'll check in on that.

@driesvints
Copy link
Member

I sent in a fix for this: #1165

@tipjoe
Copy link
Author

tipjoe commented Jan 4, 2022

Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants