{"record":{"id":"81c3ec36ddd7d25c","repo":"nodejs/node","slug":"invalid-msvs-guid-s-must-match-regex-s","errorCode":null,"errorMessage":"Invalid MSVS guid: \"%s\".  Must match regex: \"%s\".","messagePattern":"Invalid MSVS guid: \"(.+?)\"\\.  Must match regex: \"(.+?)\"\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/generator/msvs.py","lineNumber":978,"sourceCode":"\ndef _GetGuidOfProject(proj_path, spec):\n    \"\"\"Get the guid for the project.\n\n    Arguments:\n      proj_path: Path of the vcproj or vcxproj file to generate.\n      spec: The target dictionary containing the properties of the target.\n    Returns:\n      the guid.\n    Raises:\n      ValueError: if the specified GUID is invalid.\n    \"\"\"\n    # Pluck out the default configuration.\n    default_config = _GetDefaultConfiguration(spec)\n    # Decide the guid of the project.\n    guid = default_config.get(\"msvs_guid\")\n    if guid:\n        if VALID_MSVS_GUID_CHARS.match(guid) is None:\n            raise ValueError(\n                'Invalid MSVS guid: \"%s\".  Must match regex: \"%s\".'\n                % (guid, VALID_MSVS_GUID_CHARS.pattern)\n            )\n        guid = \"{%s}\" % guid\n    guid = guid or MSVSNew.MakeGuid(proj_path)\n    return guid\n\n\ndef _GetMsbuildToolsetOfProject(proj_path, spec, version):\n    \"\"\"Get the platform toolset for the project.\n\n    Arguments:\n      proj_path: Path of the vcproj or vcxproj file to generate.\n      spec: The target dictionary containing the properties of the target.\n      version: The MSVSVersion object.\n    Returns:\n      the platform toolset string or None.\n    \"\"\"","sourceCodeStart":960,"sourceCodeEnd":996,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/generator/msvs.py#L960-L996","documentation":"Raised as a ValueError when a target specifies an 'msvs_guid' that does not match the VALID_MSVS_GUID_CHARS regex. The guid is read from the default configuration's msvs_guid and validated before being wrapped in braces. An invalid guid would produce a corrupt .vcproj/.sln that Visual Studio cannot open.","triggerScenarios":"Setting 'msvs_guid' in a target's configuration to a string containing characters outside the allowed set (typically hex digits without braces/with invalid formatting). VALID_MSVS_GUID_CHARS.match returns None at msvs.py:980.","commonSituations":"Hardcoding a guid with braces already included (the code adds braces itself); using lowercase/uppercase rules mismatch; a typo or non-hex character in a hand-authored guid; copy-pasting a guid format from a different tool.","solutions":["Provide the guid as a bare hex string matching the expected pattern (no surrounding braces, valid hex characters).","Remove the msvs_guid override entirely to let gyp auto-generate a stable guid via MSVSNew.MakeGuid.","Verify the guid against VALID_MSVS_GUID_CHARS.pattern and correct any invalid characters."],"exampleFix":"// before\n'targets': [{\n  'target_name': 'foo',\n  'configurations': { 'Debug': { 'msvs_guid': '{ABC-123}' } }\n}]\n// after — bare hex, valid char set, correct length\n'targets': [{\n  'target_name': 'foo',\n  'configurations': { 'Debug': { 'msvs_guid': 'AA1BB2CC3DD4EE5FF6A7B8C9D0E1F2A3' } }\n}]","handlingStrategy":"validation","validationCode":"import re\nVALID = re.compile(r'^[A-Fa-f0-9]{32}$')\nguid = 'AA1BB2CC3DD4EE5FF6A7B8C9D0E1F2A3'\nif not VALID.match(guid):\n    raise ValueError('invalid msvs_guid format')","typeGuard":"import re\n_VALID = re.compile(r'^[A-Fa-f0-9]{32}$')\ndef is_valid_msvs_guid(g) -> bool:\n    return isinstance(g, str) and bool(_VALID.match(g))","tryCatchPattern":null,"preventionTips":["Let gyp auto-generate guids unless you have a specific stability requirement.","Provide the guid as a bare hex string without braces."],"tags":["gyp","msvs","guid","validation","windows"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}