{"record":{"id":"b3641ab627bbb29d","repo":"nodejs/node","slug":"conditions-key-cond-expr-has-len-condition","errorCode":null,"errorMessage":"{conditions_key} {cond_expr} has {len(condition) - i} unexpected trailing items","messagePattern":"(.+?) (.+?) has (.+?) unexpected trailing items","errorType":"exception","errorClass":"GypError","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/input.py","lineNumber":1142,"sourceCode":"            + \" must be at least length 2, not \"\n            + str(len(condition))\n        )\n\n    i = 0\n    result = None\n    while i < len(condition):\n        cond_expr = condition[i]\n        true_dict = condition[i + 1]\n        if not isinstance(true_dict, dict):\n            raise GypError(\n                f\"{conditions_key} {cond_expr} must be followed by a dictionary, \"\n                f\"not {type(true_dict)}\"\n            )\n        if len(condition) > i + 2 and isinstance(condition[i + 2], dict):\n            false_dict = condition[i + 2]\n            i = i + 3\n            if i != len(condition):\n                raise GypError(\n                    f\"{conditions_key} {cond_expr} has \"\n                    f\"{len(condition) - i} unexpected trailing items\"\n                )\n        else:\n            false_dict = None\n            i = i + 2\n        if result is None:\n            result = EvalSingleCondition(\n                cond_expr, true_dict, false_dict, phase, variables, build_file\n            )\n\n    return result\n\n\ndef EvalSingleCondition(cond_expr, true_dict, false_dict, phase, variables, build_file):\n    \"\"\"Returns true_dict if cond_expr evaluates to true, and false_dict\n    otherwise.\"\"\"\n    # Do expansions on the condition itself.  Since the condition can naturally","sourceCodeStart":1124,"sourceCodeEnd":1160,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/input.py#L1124-L1160","documentation":"When a condition entry has three elements [cond_expr, true_dict, false_dict] (all three present and false_dict a dict), EvalCondition advances its index by 3 and then requires that index to equal the list length. Any extra elements after the false_dict are reported as 'unexpected trailing items' with the count. This catches malformed conditions that tack on additional bare expressions or dicts beyond the standard triple.","triggerScenarios":"Writing \"['OS==\\\"mac\\\"', {true}, {false}, 'extra']\"; chaining multiple cond_exprs in a single list instead of using multiple list entries; copy-paste that duplicated the false_dict.","commonSituations":"Trying to express if/elif by listing extra items in one condition rather than as separate top-level condition entries; accidental duplicate paste of a dict.","solutions":["Express additional branches as separate entries in the outer conditions list — each entry is one [expr, true_dict, (false_dict)].","Remove the trailing elements reported by the count in the message.","For if/elif chains, use nested 'conditions' inside the false_dict."],"exampleFix":"// before\n'conditions': [\n  ['OS == \"mac\"', { 'defines': ['M'] }, { 'defines': ['L'] }, 'extra']\n],\n// after\n'conditions': [\n  ['OS == \"mac\"', { 'defines': ['M'] }, { 'defines': ['L'] }]\n],","handlingStrategy":"validation","validationCode":"def validate_condition(entry, key='conditions'):\n    if len(entry) >= 3 and isinstance(entry[2], dict):\n        assert len(entry) == 3, \\\n            f'{key} {entry[0]!r} has unexpected trailing items beyond [expr, true, false]'","typeGuard":"def has_no_trailing_items(entry) -> bool:\n    if isinstance(entry, list) and len(entry) >= 3 and isinstance(entry[2], dict):\n        return len(entry) == 3\n    return True","tryCatchPattern":null,"preventionTips":["Express if/elif chains as separate condition entries, not extra items in one entry.","After pasting a condition triple, trim any duplicated trailing dict."],"tags":["gyp","conditions","syntax","build-config"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}