{"record":{"id":"d246df27c5680672","repo":"TheAlgorithms/Python","slug":"candidates-list-should-not-be-empty","errorCode":null,"errorMessage":"Candidates list should not be empty","messagePattern":"Candidates list should not be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backtracking/combination_sum.py","lineNumber":57,"sourceCode":"\n\ndef combination_sum(candidates: list, target: int) -> list:\n    \"\"\"\n    >>> combination_sum([2, 3, 5], 8)\n    [[2, 2, 2, 2], [2, 3, 3], [3, 5]]\n    >>> combination_sum([2, 3, 6, 7], 7)\n    [[2, 2, 3], [7]]\n    >>> combination_sum([-8, 2.3, 0], 1)\n    Traceback (most recent call last):\n        ...\n    ValueError: All elements in candidates must be non-negative\n    >>> combination_sum([], 1)\n    Traceback (most recent call last):\n        ...\n    ValueError: Candidates list should not be empty\n    \"\"\"\n    if not candidates:\n        raise ValueError(\"Candidates list should not be empty\")\n\n    if any(x < 0 for x in candidates):\n        raise ValueError(\"All elements in candidates must be non-negative\")\n\n    path = []  # type: list[int]\n    answer = []  # type: list[int]\n    backtrack(candidates, path, answer, target, 0)\n    return answer\n\n\ndef main() -> None:\n    print(combination_sum([-8, 2.3, 0], 1))\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/backtracking/combination_sum.py#L39-L75","documentation":"Raised by casimir_force() in physics/casimir_effect.py when the number of zero-valued arguments among (force, area, distance) is not exactly one. The API is solve-for-one: you pass 0 for the quantity you want computed and real values for the other two. Two zeros (nothing to solve from), three zeros (all unknown), or zero zeros (nothing requested) all trigger this.","triggerScenarios":"casimir_force(force=3457e-12, area=0, distance=0) (two zeros); casimir_force(force=1e-9, area=0.002, distance=0.003) (no zeros — nothing to solve); casimir_force(0, 0, 0).","commonSituations":"Developers assume all three arguments are always supplied with real values (typical function contract) instead of the pass-zero-for-the-unknown convention; or code iterates over parameter sets and passes default 0.0 for unset fields, accidentally creating multiple zeros.","solutions":["Pass exactly one 0 for the quantity you want returned, e.g. casimir_force(force=0, area=0.002, distance=0.003) returns {'force': ...}.","If some inputs are genuinely unknown, substitute measured/estimated values rather than 0.","Add a wrapper that asserts sum(1 for v in (force, area, distance) if v == 0) == 1 before delegating."],"exampleFix":"# before\nf = casimir_force(force=0, area=0, distance=0.003)  # two zeros\n\n# after\nf = casimir_force(force=0, area=0.002, distance=0.003)  # solve for force","handlingStrategy":"validation","validationCode":"args = (force, area, distance)\nif sum(1 for v in args if v == 0) != 1:\n    raise ValueError(\"pass exactly one 0 to casimir_force for the unknown quantity\")\nresult = casimir_force(*args)","typeGuard":null,"tryCatchPattern":"try:\n    result = casimir_force(force=f, area=a, distance=d)\nexcept ValueError as e:\n    if \"must be 0\" in str(e):\n        raise ValueError(\"casimir_force needs exactly one unknown (0); got \" + repr((f, a, d))) from e\n    raise","preventionTips":["Use keyword arguments to make the solve-for-one intent explicit.","Never default unset parameters to 0 in wrappers.","Document the pass-zero convention at every call site."],"tags":["physics","api-contract","valueerror","casimir"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}