{"record":{"id":"20261c23ade1853c","repo":"donnemartin/interactive-coding-challenges","slug":"num-cannot-be-less-than-one","errorCode":null,"errorMessage":"num cannot be less than one","messagePattern":"num cannot be less than one","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb","lineNumber":117,"sourceCode":"   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Code\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"class Solution(object):\\n\",\n    \"\\n\",\n    \"    def fizz_buzz(self, num):\\n\",\n    \"        if num is None:\\n\",\n    \"            raise TypeError('num cannot be None')\\n\",\n    \"        if num < 1:\\n\",\n    \"            raise ValueError('num cannot be less than one')\\n\",\n    \"        results = []\\n\",\n    \"        for i in range(1, num + 1):\\n\",\n    \"            if i % 3 == 0 and i % 5 == 0:\\n\",\n    \"                results.append('FizzBuzz')\\n\",\n    \"            elif i % 3 == 0:\\n\",\n    \"                results.append('Fizz')\\n\",\n    \"            elif i % 5 == 0:\\n\",\n    \"                results.append('Buzz')\\n\",\n    \"            else:\\n\",\n    \"                results.append(str(i))\\n\",\n    \"        return results\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Unit Test\"","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb#L99-L135","documentation":"Raised by Solution.fizz_buzz when num < 1. The sequence is defined from 1 to num inclusive, so zero or negative counts are meaningless and rejected with ValueError. Unlike the None check, this is a domain/range validation error.","triggerScenarios":"Calling fizz_buzz(0) or fizz_buzz(-5); computing num from arithmetic that can go non-positive.","commonSituations":"Pagination/counters decrementing past zero; user-supplied counts not bounded; off-by-one in loop bounds passed as num.","solutions":["Clamp num to at least 1 if a non-empty result is required (max(1, num))","Reject at the API boundary with a 400-style message for num < 1","Fix the arithmetic that produced a zero/negative count"],"exampleFix":"# before\nSolution().fizz_buzz(count)  # count may be 0\n\n# after\nSolution().fizz_buzz(max(1, count))","handlingStrategy":"validation","validationCode":"if num >= 1:\n    Solution().fizz_buzz(num)","typeGuard":"def is_positive_int(num) -> bool:\n    return isinstance(num, int) and num >= 1","tryCatchPattern":"try:\n    Solution().fizz_buzz(num)\nexcept ValueError as e:\n    if 'less than one' in str(e):\n        num = 1\n        Solution().fizz_buzz(num)\n    else:\n        raise","preventionTips":["Clamp counts with max(1, num)","Bound user-supplied counts at the API boundary"],"tags":["fizz-buzz","range-validation","valueerror"],"backgroundTag":"argument-out-of-range","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}