{"record":{"id":"7ca703bcec9cd44c","repo":"TheAlgorithms/Python","slug":"empty-string-was-passed-to-the-function-7ca703","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_decimal.py","lineNumber":62,"sourceCode":"    0\n    >>> oct_to_decimal(\"-4055\")\n    -2093\n    >>> oct_to_decimal(\"2-0Fm\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Non-octal value was passed to the function\n    >>> oct_to_decimal(\"\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Empty string was passed to the function\n    >>> oct_to_decimal(\"19\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Non-octal value was passed to the function\n    \"\"\"\n    oct_string = str(oct_string).strip()\n    if not oct_string:\n        raise ValueError(\"Empty string was passed to the function\")\n    is_negative = oct_string[0] == \"-\"\n    if is_negative:\n        oct_string = oct_string[1:]\n    if not oct_string.isdigit() or not all(0 <= int(char) <= 7 for char in oct_string):\n        raise ValueError(\"Non-octal value was passed to the function\")\n    decimal_number = 0\n    for char in oct_string:\n        decimal_number = 8 * decimal_number + int(char)\n    if is_negative:\n        decimal_number = -decimal_number\n    return decimal_number\n\n\nif __name__ == \"__main__\":\n    from doctest import testmod\n\n    testmod()\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/octal_to_decimal.py#L44-L80","documentation":"Raised by oct_to_decimal(oct_string) in conversions/octal_to_decimal.py:62 when, after str()/strip(), the value is empty. Like its hex sibling, the function first rejects blank input with ValueError('Empty string was passed to the function') before looking at digits or the optional leading '-'.","triggerScenarios":"oct_to_decimal(''), oct_to_decimal('   '), oct_to_decimal(None) (str(None)='None' actually fails the digit check instead — only truly empty/blank strings hit this branch), or empty fields from argparse/file parsing.","commonSituations":"Optional CLI flags or config keys that default to '' when unset; iterating over split() results that include empty strings; form fields left blank.","solutions":["Treat blank as missing before calling: if not str(value).strip(): handle the missing case","Default to '0' when zero is the sensible interpretation: oct_to_decimal(value.strip() or '0')","Use argparse defaults/validation so empty strings never reach the converter"],"exampleFix":"# before\noct_to_decimal(args.octal)  # unset optional flag '' -> ValueError\n\n# after\nval = args.octal.strip() if args.octal else ''\nif not val:\n    raise SystemExit('octal value required')\noct_to_decimal(val)","handlingStrategy":"validation","validationCode":"oct_string = str(oct_string).strip()\nif not oct_string:\n    raise ValueError('octal value is required')","typeGuard":"def is_nonempty_str(v: object) -> TypeGuard[str]:\n    return isinstance(v, str) and bool(v.strip())","tryCatchPattern":null,"preventionTips":["Reject blank optional inputs at the CLI/config layer","Default to '0' when zero is the intended empty semantics","str()-normalize inputs early since the function itself calls str()"],"tags":["python","value-error","octal","decimal","empty-input"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}