Magento2: Type Error occurred when creating object: Magento\Framework\Communication\Config\Data

Created on 7 May 2019  路  11Comments  路  Source: magento/magento2

Following the instructions on https://devdocs.magento.com/guides/v2.3/comp-mgr/cli/cli-upgrade.html for upgrading Magento, I got this error when executing the command "php bin/magento setup:upgrade"

Preconditions (*)

  1. Upgraded from 2.2.3 -> 2.3.1
  2. PHP Version 7.2.16

Steps to reproduce (*)

  1. Starting with a 2.2.3 installation, in Magento root dir:
  2. php bin/magento maintenance:enable
  3. composer require magento/product-community-edition=2.3.1 --no-update
  4. composer require --dev phpunit/phpunit:~6.2.0 friendsofphp/php-cs-fixer:~2.10.1 lusitanian/oauth:~0.8.10 pdepend/pdepend:2.5.2 sebastian/phpcpd:~3.0.0 squizlabs/php_codesniffer:3.2.2 --no-update
  5. composer remove --dev sjparkinson/static-review fabpot/php-cs-fixer --no-update
  6. Open composer.json and edit the "autoload": "psr-4" section to include "Zend\Mvc\Controller\": "setup/src/Zend/Mvc/Controller/":

"autoload": {
"psr-4": {
"Magento\Framework\": "lib/internal/Magento/Framework/",
"Magento\Setup\": "setup/src/Magento/Setup/",
"Magento\": "app/code/Magento/",
"Zend\Mvc\Controller\": "setup/src/Zend/Mvc/Controller/"
},
...
}

  1. composer create-project --repository=https://repo.magento.com magento/project-community-edition=2.3.1 temp_dir --no-install
  2. rm -rf update
  3. mv temp_dir/update .
  4. rm -rf temp_dir
  5. composer update
  6. bin/magento cache:clean
  7. rm -rf var/cache/*
  8. rm -rf var/page_cache/*
  9. rm -rf generated/code/*
  10. bin/magento setup:upgrade

Expected result (*)

  1. The command "bin/magento setup:upgrade" should finish without errors

Actual result (*)

  1. The command "bin/magento setup:upgrade" breaks with message:
    Type Error occurred when creating object: Magento\Framework\Communication\Config\Data

In the system.log I see the whole message:
[2019-05-07 13:47:47] main.CRITICAL: Type Error occurred when creating object: Magento\Framework\Communication\Config\Data, Argument 2 passed to Magento\Framework\Reflection\TypeProcessor::resolveFullyQualifiedClassName() must be of the type string, null given, called in /var/www/vhosts/schuhjaeger.at/magento2_test/shop-v2/vendor/magento/framework/Reflection/TypeProcessor.php on line 535 [] []

This is the function from TypeProcess.php:

`
/**
* Get the parameter type
*
* @param ParameterReflection $param
* @return string
* @throws \LogicException
*/
public function getParamType(ParameterReflection $param)
{
$type = $param->detectType();
if ($type === 'null') {
throw new \LogicException(sprintf(
'@param annotation is incorrect for the parameter "%s" in the method "%s:%s".'
. ' First declared type should not be null. E.g. string|null',
$param->getName(),
$param->getDeclaringClass()->getName(),
$param->getDeclaringFunction()->name
));
}
if ($type === 'array') {
// try to determine class, if it's array of objects
$paramDocBlock = $this->getParamDocBlockTag($param);
$paramTypes = $paramDocBlock->getTypes();
$paramType = array_shift($paramTypes);

        $paramType = $this->resolveFullyQualifiedClassName($param->getDeclaringClass(), $paramType);

        return strpos($paramType, '[]') !== false ? $paramType : "{$paramType}[]";
    }
    return $this->resolveFullyQualifiedClassName($param->getDeclaringClass(), $type);
}

`

According to the error message, the variable $type is null.

How can I solve this?

Thank you very much in advance!

Format is valid

Most helpful comment

For anyone want to fix this issue.
The root cause is magento read the configurations files of queue and it try to resolve the parameter in consumer handler method.

  • How to fix?
    add PHPDOC block for all consumer class in your custom module.
  • How to find all consumer class?
    you can set break point debugger in vendor/magento/framework/Reflection/MethodsMap.php or just wrap this method in try/catch block and print the class you need to fix.
    image

All 11 comments

Hi @akamenew. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@akamenew do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @GovindaSharma. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

Hi @shikhamis11. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

@akamenew Thank you for your report, I followed the same step and I am not able to reproduce the issue. Let me know If It requires any additional step too to reproduce the issue.

@shikhamis11 Actually that were all the steps I went through to observe this behaviour. Do you have any idea on how to resolve this? I have tried different approaches (like cleaning cache, deleting stuff in generated and var folder) but nothing worked yet. Any help is highly appreciated.

Im also having the same issue. Upgraded from 2.3.0 to 2.3.1, Error getting thrown after Module 'Magento_AMQP' in setup:upgrade. I am using AMQP in my build.
Screenshot 2019-05-09 at 09 52 22

For some more information:
The error is occurring on trying to define the "type" for Magento\Framework\MessageQueue\Consumer::process docblock. In the screenshot you can see the Docblock for the method. It has a param.

Screenshot 2019-05-09 at 10 13 25

Problem is the Zend\Code\Reflection\ParameterReflection::detectType method is returning null. This is because the DocBlock params aren't being picked up on line 107, but as you can see in the screenshot the param type is available on the Interface. In the screenshot below you can see there are no tags.

Screenshot 2019-05-09 at 10 36 11

I also got his error but only with payment module,

I have a payment module for Magento for one Croatian online payment provider, i tried it to install on Magento 2.3.1 and everything is fine but when i want to go on Checkout it says https://www.example.com/rest/default/V1/guest-carts/auIzs7o1NSN0KyEoq6jHv5MJkbcnUbC7/estimate-shipping-methods - Failed to load resource: the server responded with a status of 500 () and i have no shipping methods?

Module 'Magento_Amqp':
Type Error occurred when creating object: Magento\Framework\Communication\Config\Data

debug.log

[2019-06-06 11:57:30] main.CRITICAL: Type Error occurred when creating object: Magento\Framework\Communication\Config\Data, Argument 2 passed to Magento\Framework\Reflection\TypeProcessor::resolveFullyQualifiedClassName() must be of the type string, null given, called in /home/nulledzo/capriolo.hr/vendor/magento/framework/Reflection/TypeProcessor.php on line 535 [] [] [2019-06-06 11:57:30] main.ERROR: Type Error occurred when creating object: Magento\Framework\Communication\Config\Data [] []

system.log

[2019-06-06 11:57:30] main.CRITICAL: Type Error occurred when creating object: Magento\Framework\Communication\Config\Data, Argument 2 passed to Magento\Framework\Reflection\TypeProcessor::resolveFullyQualifiedClassName() must be of the type string, null given, called in /home/nulledzo/capriolo.hr/vendor/magento/framework/Reflection/TypeProcessor.php on line 535 [] [] [2019-06-06 11:57:30] main.ERROR: Type Error occurred when creating object: Magento\Framework\Communication\Config\Data [] []

Report:

{"0":"Type Error occurred when creating object: Magento\Framework\Communication\Config\Data","1":"#1 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:70]\n#2 Magento\Framework\ObjectManager\ObjectManager->get() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:160]\n#3 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:246]\n#4 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34]\n#5 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59]\n#6 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:70]\n#7 Magento\Framework\ObjectManager\ObjectManager->get() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:160]\n#8 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:246]\n#9 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34]\n#10 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59]\n#11 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:70]\n#12 Magento\Framework\ObjectManager\ObjectManager->get() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:160]\n#13 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:246]\n#14 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34]\n#15 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59]\n#16 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:70]\n#17 Magento\Framework\ObjectManager\ObjectManager->get() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:160]\n#18 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:246]\n#19 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34]\n#20 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59]\n#21 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:70]\n#22 Magento\Framework\ObjectManager\ObjectManager->get() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:160]\n#23 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:246]\n#24 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34]\n#25 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59]\n#26 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:70]\n#27 Magento\Framework\ObjectManager\ObjectManager->get() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:196]\n#28 Magento\Framework\ObjectManager\Factory\AbstractFactory->parseArray() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:172]\n#29 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:246]\n#30 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34]\n#31 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59]\n#32 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:70]\n#33 Magento\Framework\ObjectManager\ObjectManager->get() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:160]\n#34 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() called at [vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:246]\n#35 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgumentsInRuntime() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:34]\n#36 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() called at [vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:59]\n#37 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:70]\n#38 Magento\Framework\ObjectManager\ObjectManager->get() called at [vendor/magento/framework/App/Http.php:135]\n#39 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:24]\n#40 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:258]\n#41 Magento\Framework\App\Bootstrap->run() called at [index.php:39]\n","url":"/rest/default/V1/guest-carts/auIzs7o1NSN0KyEoq6jHv5MJkbcnUbC7/estimate-shipping-methods","script_name":"/index.php"}


Any Help???

For anyone want to fix this issue.
The root cause is magento read the configurations files of queue and it try to resolve the parameter in consumer handler method.

  • How to fix?
    add PHPDOC block for all consumer class in your custom module.
  • How to find all consumer class?
    you can set break point debugger in vendor/magento/framework/Reflection/MethodsMap.php or just wrap this method in try/catch block and print the class you need to fix.
    image

@akamenew @just-tom just-tom
change function
Path: Magento\Framework\Reflection\TypeProcessor

public function getParamType(ParameterReflection $param)
{
$type = $param->detectType();
if ($type === 'null') {
throw new \LogicException(sprintf(
'@param annotation is incorrect for the parameter "%s" in the method "%s:%s".'
. ' First declared type should not be null. E.g. string|null',
$param->getName(),
$param->getDeclaringClass()->getName(),
$param->getDeclaringFunction()->name
));
}
if ($type === 'array') {
// try to determine class, if it's array of objects
$paramDocBlock = $this->getParamDocBlockTag($param);
$paramTypes = $paramDocBlock->getTypes();
$paramType = array_shift($paramTypes);

        $paramType = $this->resolveFullyQualifiedClassName($param->getDeclaringClass(), $paramType);

        return strpos($paramType, '[]') !== false ? $paramType : "{$paramType}[]";
    }

    return $type;
}

Im also having the same issue. Upgraded from 2.3.0 to 2.3.1, Error getting thrown after Module 'Magento_AMQP' in setup:upgrade. I am using AMQP in my build.
Screenshot 2019-05-09 at 09 52 22

What is solution for this ..? i am slo got same issue and why ?

Was this page helpful?
0 / 5 - 0 ratings