{"record":{"id":"311a2a0357ae089b","repo":"twigphp/Twig","slug":"node-s-does-not-exist-for-node-s","errorCode":null,"errorMessage":"Node \"%s\" does not exist for Node \"%s\".","messagePattern":"Node \"(.+?)\" does not exist for Node \"(.+?)\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Node/Node.php","lineNumber":228,"sourceCode":"    {\n        unset($this->attributes[$name]);\n    }\n\n    /**\n     * @param string|int $name\n     */\n    public function hasNode(string $name): bool\n    {\n        return isset($this->nodes[$name]);\n    }\n\n    /**\n     * @param string|int $name\n     */\n    public function getNode(string $name): self\n    {\n        if (!isset($this->nodes[$name])) {\n            throw new \\LogicException(\\sprintf('Node \"%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->nodeNameDeprecations[$name])) {\n            $dep = $this->nodeNameDeprecations[$name];\n            if ($dep->getNewName()) {\n                trigger_deprecation($dep->getPackage(), $dep->getVersion(), 'Getting node \"%s\" on a \"%s\" class is deprecated, get the \"%s\" node instead.', $name, static::class, $dep->getNewName());\n            } else {\n                trigger_deprecation($dep->getPackage(), $dep->getVersion(), 'Getting node \"%s\" on a \"%s\" class is deprecated.', $name, static::class);\n            }\n        }\n\n        return $this->nodes[$name];\n    }\n\n    /**\n     * @param string|int $name\n     */","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Node/Node.php#L210-L246","documentation":"Node::getNode() throws when the requested child node key is absent from the node's $nodes map. Twig nodes hold their children in named slots (e.g. 'body', 'test', 'left'); asking for a slot this node type never populates indicates the caller assumed the wrong node shape. It is a LogicException for programming errors during compilation or visiting.","triggerScenarios":"Calling $node->getNode('body') on a node type without a 'body' child (e.g. on a NameExpression instead of an IfNode); a custom NodeVisitor or optimizer pass that assumes every node has particular children; compiler code shared across node classes with different child layouts.","commonSituations":"Custom Twig node visitors traversing trees and unconditionally fetching well-known child names; extensions written against an older Twig version where node child names changed; refactored custom nodes where a child was made optional but compiler code still requires it.","solutions":["Use $node->hasNode('name') before getNode('name'), or iterate with $node->getIterator()/foreach instead of named access.","Verify the concrete node class and the child slot names it actually defines.","Branch on instanceof before accessing children so each node type reads its own slots.","If it appeared after a Twig upgrade, check the CHANGELOG for renamed node children and update the extension."],"exampleFix":"// before\n$body = $node->getNode('body');\n// after\n$body = $node->hasNode('body') ? $node->getNode('body') : null;","handlingStrategy":"type-guard","validationCode":"if (!$node->hasNode('body')) {\n    throw new \\RuntimeException('Expected \"body\" child on ' . get_class($node));\n}","typeGuard":"$child = $node->hasNode($name) ? $node->getNode($name) : null;","tryCatchPattern":"try {\n    $child = $node->getNode('body');\n} catch (\\LogicException $e) {\n    $child = null; // node type has no 'body' child\n}","preventionTips":["Check hasNode() before getNode(), or iterate children generically.","Use instanceof checks so each node type accesses its own child slots.","After upgrading Twig, verify node child names used by custom visitors/extensions."],"tags":["twig","node","child-node","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"}