{"record":{"id":"1112772d3ab5e3ac","repo":"nodejs/node","slug":"value-must-be-one-of-0-1-2-got-s","errorCode":null,"errorMessage":"value must be one of [0, 1, 2]; got %s","messagePattern":"value must be one of \\[0, 1, 2\\]; got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/MSVSSettings.py","lineNumber":363,"sourceCode":"\n    _msvs_validators[tool.msvs_name][msvs_name] = _boolean.ValidateMSVS\n    _msvs_to_msbuild_converters[tool.msvs_name][msvs_name] = _Translate\n\n\ndef _CustomGeneratePreprocessedFile(tool, msvs_name):\n    def _Translate(value, msbuild_settings):\n        tool_settings = _GetMSBuildToolSettings(msbuild_settings, tool)\n        if value == \"0\":\n            tool_settings[\"PreprocessToFile\"] = \"false\"\n            tool_settings[\"PreprocessSuppressLineNumbers\"] = \"false\"\n        elif value == \"1\":  # /P\n            tool_settings[\"PreprocessToFile\"] = \"true\"\n            tool_settings[\"PreprocessSuppressLineNumbers\"] = \"false\"\n        elif value == \"2\":  # /EP /P\n            tool_settings[\"PreprocessToFile\"] = \"true\"\n            tool_settings[\"PreprocessSuppressLineNumbers\"] = \"true\"\n        else:\n            raise ValueError(\"value must be one of [0, 1, 2]; got %s\" % value)\n\n    # Create a bogus validator that looks for '0', '1', or '2'\n    msvs_validator = _Enumeration([\"a\", \"b\", \"c\"]).ValidateMSVS\n    _msvs_validators[tool.msvs_name][msvs_name] = msvs_validator\n    msbuild_validator = _boolean.ValidateMSBuild\n    msbuild_tool_validators = _msbuild_validators[tool.msbuild_name]\n    msbuild_tool_validators[\"PreprocessToFile\"] = msbuild_validator\n    msbuild_tool_validators[\"PreprocessSuppressLineNumbers\"] = msbuild_validator\n    _msvs_to_msbuild_converters[tool.msvs_name][msvs_name] = _Translate\n\n\nfix_vc_macro_slashes_regex_list = (\"IntDir\", \"OutDir\")\nfix_vc_macro_slashes_regex = re.compile(\n    r\"(\\$\\((?:%s)\\))(?:[\\\\/]+)\" % \"|\".join(fix_vc_macro_slashes_regex_list)\n)\n\n# Regular expression to detect keys that were generated by exclusion lists\n_EXCLUDED_SUFFIX_RE = re.compile(\"^(.*)_excluded$\")","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/MSVSSettings.py#L345-L381","documentation":"A bespoke _Translate function for the VS 'PreprocessToFile/PreprocessSuppressLineNumbers' setting raises ValueError('value must be one of [0, 1, 2]; got %s') when the preprocess level is anything other than the literal strings '0', '1', or '2'. These map to: 0 = no preprocessing, 1 = /P (preprocess to file, keep line numbers), 2 = /EP /P (preprocess, strip line numbers). A dummy _Enumeration(['a','b','c']) is used as the MSVS validator only to accept indices 0..2, but the actual conversion enforces the string forms.","triggerScenarios":"Setting the preprocess setting to an integer 0/1/2 (Python int, not string), to '3', or to any out-of-set string; relying on the dummy enumeration validator without realizing the converter re-checks.","commonSituations":"Programmatically assigning an int instead of '0'/'1'/'2'; copy-pasting 'yes'/'no'; misreading the dummy enumeration as accepting arbitrary values.","solutions":["Use exactly one of the strings '0', '1', or '2'.","If the value is computed as an int, str() it and clamp to {0,1,2}.","Verify the setting name against the registration block in MSVSSettings.py around line 363."],"exampleFix":"# before\npreprocess_level = 1   # int -> fails\n\n# after\npreprocess_level = '1'","handlingStrategy":"validation","validationCode":"def coerce_preprocess_level(value):\n    s = str(value)\n    if s not in ('0', '1', '2'):\n        raise ValueError('preprocess level must be 0/1/2, got %r' % value)\n    return s","typeGuard":"def is_valid_preprocess_level(value) -> bool:\n    return str(value) in ('0', '1', '2')","tryCatchPattern":"try:\n    _Translate(my_value, msbuild_settings)\nexcept ValueError:\n    my_value = coerce_preprocess_level(my_value)\n    _Translate(my_value, msbuild_settings)","preventionTips":["Always pass the preprocess level as one of the strings '0','1','2'.","Do not assume the dummy _Enumeration validator is sufficient; the converter re-checks.","Str()-ify computed int values and clamp to {0,1,2}."],"tags":["gyp","msvs","msbuild","enumeration","preprocess","validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}