how to debug “ ”Unable to get a property on a non-object." in custom operations?

北城余情 提交于 2019-12-13 03:34:57

问题


I'm getting the error

"hydra:description": "Unable to get a property on a non-object.",

when trying to implement a custom operation. I'm trying to figure out what causes this problem and while I've found a dozen or so wild guesses on both stackoverflow and elsewhere, none of the solutions posted there work for me.

I'm trying to figure out how to debug this problem. The trace and info included with the error message is less than helpful:

{
  "@context": "/api/contexts/Error",
  "@type": "hydra:Error",
  "hydra:title": "An error occurred",
  "hydra:description": "Unable to get a property on a non-object.",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/Users/tom/Code/api-platform/vendor/symfony/expression-language/Node/GetAttrNode.php",
      "line": 73,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\ExpressionLanguage\\Node",
      "short_class": "GetAttrNode",
      "class": "Symfony\\Component\\ExpressionLanguage\\Node\\GetAttrNode",
      "type": "->",
      "function": "evaluate",
      "file": "/Users/tom/Code/api-platform/vendor/symfony/expression-language/Node/GetAttrNode.php",
      "line": 71,
      "args": [
        [
          "array",
          {
            "constant": [
              "array",
              {
                "compiler": [
                  "object",
                  "Closure"
                ],
                "evaluator": [
                  "object",
                  "Closure"
                ]
              }
            ],
            "is_granted": [
              "array",
              {
                "compiler": [
                  "object",
                  "Closure"
                ],
                "evaluator": [
                  "object",
                  "Closure"
                ]
              }

all of which tells me absolutely nothing about which property on which object it is looking for, what data it is inspecting, and where I should be looking for the problem.

I've tried adding var_dump() statements into both my own code and places like before line 73 in GetAttrNode.php and it doesn't help. It appears that the code does not even hit my controller. I'm fairly certain that the problem isn't in my controller, as at this point the controller is nothing but the stub as described in the documentation (https://api-platform.com/docs/core/operations#creating-custom-operations-and-controllers).

How can I debug this issue and figure out where the problem is?


回答1:


According to the stack trace you provided, the error is in your security rule. Check the value of the is_granted attribute in your class marked with the @ApiResource annotation, it has some kind of errors.



来源:https://stackoverflow.com/questions/50895416/how-to-debug-unable-to-get-a-property-on-a-non-object-in-custom-operations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!