{"record":{"id":"07fb32e277c617d0","repo":"twigphp/Twig","slug":"attribute-s-does-not-exist-for-node-s","errorCode":null,"errorMessage":"Attribute \"%s\" does not exist for Node \"%s\".","messagePattern":"Attribute \"(.+?)\" does not exist for Node \"(.+?)\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Node/Node.php","lineNumber":173,"sourceCode":"     */\n    public function setNodeTag(string $tag): void\n    {\n        if ($this->tag) {\n            throw new \\LogicException('The tag of a node can only be set once.');\n        }\n\n        $this->tag = $tag;\n    }\n\n    public function hasAttribute(string $name): bool\n    {\n        return \\array_key_exists($name, $this->attributes);\n    }\n\n    public function getAttribute(string $name)\n    {\n        if (!\\array_key_exists($name, $this->attributes)) {\n            throw new \\LogicException(\\sprintf('Attribute \"%s\" does not exist for Node \"%s\".', $name, static::class));\n        }\n\n        $triggerDeprecation = \\func_num_args() > 1 ? func_get_arg(1) : true;\n        if ($triggerDeprecation && isset($this->attributeNameDeprecations[$name])) {\n            $dep = $this->attributeNameDeprecations[$name];\n            if ($dep->getNewName()) {\n                trigger_deprecation($dep->getPackage(), $dep->getVersion(), 'Getting attribute \"%s\" on a \"%s\" class is deprecated, get the \"%s\" attribute instead.', $name, static::class, $dep->getNewName());\n            } else {\n                trigger_deprecation($dep->getPackage(), $dep->getVersion(), 'Getting attribute \"%s\" on a \"%s\" class is deprecated.', $name, static::class);\n            }\n        }\n\n        return $this->attributes[$name];\n    }\n\n    public function setAttribute(string $name, $value): void\n    {\n        $triggerDeprecation = \\func_num_args() > 2 ? func_get_arg(2) : true;","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Node/Node.php#L155-L191","documentation":"Node::getAttribute() throws when the requested attribute key does not exist on the node's $attributes array. Twig nodes store metadata (names, values, flags) in attributes; requesting a key the node never had means the caller assumes a node shape that differs from the actual node. It is a LogicException signaling a programming error in a compiler, visitor, or extension.","triggerScenarios":"Calling $node->getAttribute('name') on a node type that has no 'name' attribute, e.g. calling NodeExpression Name methods on a ConstantExpression, or a custom visitor/compiler pass assuming every node carries attributes like 'value', 'raw', or 'always_defined'.","commonSituations":"Custom Twig extensions or dump-style debug visitors inspecting heterogeneous nodes and assuming a uniform attribute set; upgrading Twig where a node attribute was renamed/removed (attribute deprecations exist in this code) while custom code still requests the old name; copy-pasted compiler code applied to the wrong node class.","solutions":["Call $node->hasAttribute('name') before getAttribute(), or use $node->getAttribute('name', false) where deprecation-triggering argument applies.","Check the actual node class (get_class($node)) and only request attributes that class defines.","If handling multiple node types, branch on instanceof before accessing attributes.","If caused by a Twig upgrade, consult the CHANGELOG for renamed node attributes and update custom code."],"exampleFix":"// before\n$name = $node->getAttribute('name');\n// after\n$name = $node->hasAttribute('name') ? $node->getAttribute('name') : null;","handlingStrategy":"type-guard","validationCode":"if (!$node->hasAttribute('name')) {\n    throw new \\RuntimeException('Unexpected node shape: no \"name\" attribute on ' . get_class($node));\n}","typeGuard":"$attr = $node->hasAttribute($name) ? $node->getAttribute($name) : null;","tryCatchPattern":"try {\n    $value = $node->getAttribute('name');\n} catch (\\LogicException $e) {\n    $value = null; // attribute absent for this node type\n}","preventionTips":["Check hasAttribute() before getAttribute().","Branch on instanceof to only read attributes the concrete node class defines.","After Twig upgrades, diff node attribute names used by your extensions against the CHANGELOG."],"tags":["twig","node","attribute-access","logic-exception"],"backgroundTag":"resource-not-found","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}