{"record":{"id":"dc524259dabfb5dc","repo":"ramsey/uuid","slug":"invalid-node-value","errorCode":null,"errorMessage":"Invalid node value","messagePattern":"Invalid node value","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Generator/DefaultTimeGenerator.php","lineNumber":113,"sourceCode":"     * @param int | string | null $node A node value that may be used to override the node provider\n     *\n     * @return string 6-byte binary string representation of the node\n     *\n     * @throws InvalidArgumentException\n     */\n    private function getValidNode(int | string | null $node): string\n    {\n        if ($node === null) {\n            $node = $this->nodeProvider->getNode();\n        }\n\n        // Convert the node to hex if it is still an integer.\n        if (is_int($node)) {\n            $node = dechex($node);\n        }\n\n        if (!preg_match('/^[A-Fa-f0-9]+$/', (string) $node) || strlen((string) $node) > 12) {\n            throw new InvalidArgumentException('Invalid node value');\n        }\n\n        return (string) hex2bin(str_pad((string) $node, 12, '0', STR_PAD_LEFT));\n    }\n}\n","sourceCodeStart":95,"sourceCodeEnd":119,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Generator/DefaultTimeGenerator.php#L95-L119","documentation":"DefaultTimeGenerator::getValidNode() accepts the node as null (from the node provider), an int, or a hex string, but requires it to match /^[A-Fa-f0-9]+$/ and be at most 12 hex digits (48 bits); otherwise it throws InvalidArgumentException('Invalid node value').","triggerScenarios":"Passing a MAC address with separators to Uuid::uuid1($node) ('00:11:22:33:44:55' or '00-11-22-33-44-55'); a node with '0x' prefix or whitespace; a negative int (dechex(-1) produces 16 hex chars); any int/string above 0xffffffffffff.","commonSituations":"Formatting a MAC from config, ifconfig, or a cloud metadata service without stripping separators; passing 64-bit ints as node; copy/pasting node values with newlines from config files.","solutions":["Strip separators and prefixes: $node = str_replace([':', '-', '0x'], '', strtolower(trim($mac))).","Pass 12 hex digits, or a non-negative int <= 281474976710655 (0xffffffffffff).","Wrap the node in Ramsey\\Uuid\\Type\\Hexadecimal at construction so format expectations are explicit."],"exampleFix":"// before\n$uuid = Uuid::uuid1($nodeProvider, null, $macAddress); // '3c:22:fb:1a:2b:3c' -> InvalidArgumentException\n\n// after\n$node = str_replace([':', '-'], '', trim($macAddress)); // '3c22fb1a2b3c'\n$uuid = Uuid::uuid1(null, null, $node);","handlingStrategy":"validation","validationCode":"function normalizeNode(string|int|null $node): ?string\n{\n    if ($node === null) {\n        return null;\n    }\n    $hex = is_int($node)\n        ? dechex($node)\n        : strtolower(str_replace([':', '-', '0x'], '', trim($node)));\n\n    if (!preg_match('/^[a-f0-9]{1,12}$/', $hex)) {\n        throw new InvalidArgumentException(sprintf('invalid node value: %s', (string) $node));\n    }\n\n    return $hex;\n}\n\n$uuid = Uuid::uuid1(null, null, normalizeNode($configuredNode));","typeGuard":"function isUsableNodeValue(string|int $node): bool\n{\n    $hex = is_int($node) ? dechex($node) : $node;\n\n    return (bool) preg_match('/^[A-Fa-f0-9]{1,12}$/', $hex);\n}","tryCatchPattern":"try {\n    $uuid = Uuid::uuid1($nodeProvider, null, $node);\n} catch (\\Ramsey\\Uuid\\Exception\\InvalidArgumentException $e) {\n    $uuid = Uuid::uuid1(); // regenerate with the provider's node\n}","preventionTips":["Strip ':', '-' and '0x' from MAC addresses before passing them as node.","Pass at most 12 hex digits or an int <= 281474976710655; negative ints always fail.","Wrap node config in a Hexadecimal type to make the format explicit.","Validate node values once where they enter configuration, not at each uuid1() call."],"tags":["php","ramsey-uuid","time-generator","uuid-v1","node-id","mac-address"],"backgroundTag":"invalid-node-value","analyzedSha":"da5b521600a707d2dd097598464bd3090de850f5","analyzedAt":"2026-08-21T01:35:29.252Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}