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

Undefined array key "file" issue on DoctrineBundle CI #44

Closed
dmaicher opened this issue Jun 2, 2023 · 10 comments · Fixed by #53
Closed

Undefined array key "file" issue on DoctrineBundle CI #44

dmaicher opened this issue Jun 2, 2023 · 10 comments · Fixed by #53
Assignees

Comments

@dmaicher
Copy link

dmaicher commented Jun 2, 2023

We have the following issue on DoctrineBundle CI:

1) Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Compiler\IdGeneratorPassTest::testRepositoryServiceWiring
Undefined array key "file"

/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/Deprecation.php:189
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/Deprecation.php:99
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php:83
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1109
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1234
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1180
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1657
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1134
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1234
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1180
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1078
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1234
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1180
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1657
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1134
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1234
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1180
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:1078
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:608
/home/runner/work/DoctrineBundle/DoctrineBundle/vendor/symfony/dependency-injection/ContainerBuilder.php:553
/home/runner/work/DoctrineBundle/DoctrineBundle/Tests/DependencyInjection/Compiler/IdGeneratorPassTest.php:121

I get the same error locally and $backtrace[1] only contains:

array(3) {
  ["function"]=>
  string(11) "__construct"
  ["class"]=>
  string(43) "Doctrine\ORM\Mapping\Driver\AttributeDriver"
  ["type"]=>
  string(2) "->"
}
@dmaicher
Copy link
Author

dmaicher commented Jun 2, 2023

Also see comment from @stof : doctrine/DoctrineBundle#1667 (comment)

@greg0ire
Copy link
Member

greg0ire commented Jun 2, 2023

I witnessed something similar this morning when trying DOCTRINE_DEPRECATIONS=trigger vendor/bin/phpunit on doctrine/orm 3 (might be easier to reproduce).

@stof
Copy link
Member

stof commented Jun 2, 2023

This was not called by static analysis because the doctrine/deprecations codebase uses @param array<mixed> $backtrace instead of describing the shape of frames.

@greg0ire
Copy link
Member

greg0ire commented Jun 2, 2023

That and there is no static analysis setup on doctrine/deprecations 🤣 (yet)

@greg0ire
Copy link
Member

greg0ire commented Jun 2, 2023

Let's start there I guess: #45

@greg0ire
Copy link
Member

greg0ire commented Jun 2, 2023

On the ORM, I think it happens because of eval() as well, because there is a call to getMockForAbstractClass(): https://github.com/doctrine/orm/blob/8b1ce48e79284c49d62156990236d0e31961582b/tests/Doctrine/Tests/OrmTestCase.php#L147

@stof stof self-assigned this Jun 2, 2023
@stof
Copy link
Member

stof commented Jun 2, 2023

benefit of using 2 SA tools:

At level 7, phpstan detects some of the broken usages (not all of them due to the unprecise phpdoc when passing the backtrace to a private method, but it finds the ones when the output of debug_backtrace is used directly). Psalm does not detect those, because its own stubs for debug_backtrace are marking the keys as mandatory.

@stof
Copy link
Member

stof commented Jun 2, 2023

I'm working on fixing this

@stof
Copy link
Member

stof commented Jun 2, 2023

According to https://www.php.net/manual/fr/function.debug-backtrace.php#59713 there is another case where both file and lines might be missing: when the frame corresponds to a builtin function.

@stof
Copy link
Member

stof commented Jun 2, 2023

Trying to reproduce it for tests, this is not related to eval'd code. Such code has a file key looking like that: /path/DeprecationTest.php(322) : eval()'d code.

The case where the file is missing is for frames corresponding to native code.
Looking at the stack trace above, vendor/symfony/dependency-injection/ContainerBuilder.php:1109 is this line of code:

$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);

As the AttributeDriver triggers an exception in its constructor, we end up with frame 0 (the deprecation trigger) being called in the AttributeDriver constructor and frame 1 (the constructor) being called inside ReflectionClass::newInstanceArgs

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

Successfully merging a pull request may close this issue.

3 participants