{"record":{"id":"b698b5ebbad32ecd","repo":"TheAlgorithms/Python","slug":"empty-string-was-passed-to-the-function-b698b5","errorCode":null,"errorMessage":"Empty string was passed to the function","messagePattern":"Empty string was passed to the function","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/octal_to_binary.py","lineNumber":33,"sourceCode":"    >>> octal_to_binary(\"17\")\n    '001111'\n    >>> octal_to_binary(\"7\")\n    '111'\n    >>> octal_to_binary(\"Av\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Non-octal value was passed to the function\n    >>> octal_to_binary(\"@#\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Non-octal value was passed to the function\n    >>> octal_to_binary(\"\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Empty string was passed to the function\n    \"\"\"\n    if not octal_number:\n        raise ValueError(\"Empty string was passed to the function\")\n\n    binary_number = \"\"\n    octal_digits = \"01234567\"\n    for digit in octal_number:\n        if digit not in octal_digits:\n            raise ValueError(\"Non-octal value was passed to the function\")\n\n        binary_digit = \"\"\n        value = int(digit)\n        for _ in range(3):\n            binary_digit = str(value % 2) + binary_digit\n            value //= 2\n        binary_number += binary_digit\n\n    return binary_number\n\n\nif __name__ == \"__main__\":","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/octal_to_binary.py#L15-L51","documentation":"Raised by octal_to_binary(octal_number) in conversions/octal_to_binary.py:33 when the input string is falsy — empty ('') or None. Unlike sibling functions in this repo it does not strip whitespace first, so a blank-but-non-empty string like ' ' instead fails the digit check (' ' is not in '01234567'). Empty input means no digits to expand into 3-bit groups, hence ValueError('Empty string was passed to the function').","triggerScenarios":"octal_to_binary(''), octal_to_binary(None) (falsy), or a loop over tokens where one token is empty.","commonSituations":"Splitting input on a delimiter that yields empty fields (trailing separators); optional parameters defaulting to '' or None; reading columns from a data file with missing values.","solutions":["Skip or handle empty tokens before calling: if not octal_number: continue","Strip and default: octal_number = (octal_number or '').strip() or '0'","Avoid splitting with keepempty behavior: [t for t in s.split(',') if t.strip()]"],"exampleFix":"# before\ntokens = '755,,644'.split(',')\nfor t in tokens:\n    octal_to_binary(t)  # '' -> ValueError\n\n# after\nfor t in '755,,644'.split(','):\n    if t.strip():\n        octal_to_binary(t)","handlingStrategy":"validation","validationCode":"octal_number = (octal_number or '').strip()\nif not octal_number:\n    raise ValueError('octal string is required')","typeGuard":"def is_nonempty_octal_input(v: object) -> TypeGuard[str]:\n    return isinstance(v, str) and bool(v.strip())","tryCatchPattern":null,"preventionTips":["Filter empty tokens when splitting delimiter-joined input","Note this function does not strip whitespace itself — ' ' fails as non-octal","Default missing optional values explicitly rather than '' / None"],"tags":["python","value-error","octal","binary","empty-input"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}