{"record":{"id":"66b2dd227cf50aa3","repo":"TheAlgorithms/Python","slug":"no-value-was-passed-to-the-function","errorCode":null,"errorMessage":"No value was passed to the function","messagePattern":"No value was passed to the function","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/hex_to_bin.py","lineNumber":34,"sourceCode":"    >>> hex_to_bin(\"   12f   \")\n    100101111\n    >>> hex_to_bin(\"FfFf\")\n    1111111111111111\n    >>> hex_to_bin(\"-fFfF\")\n    -1111111111111111\n    >>> hex_to_bin(\"F-f\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Invalid value was passed to the function\n    >>> hex_to_bin(\"\")\n    Traceback (most recent call last):\n        ...\n    ValueError: No value was passed to the function\n    \"\"\"\n\n    hex_num = hex_num.strip()\n    if not hex_num:\n        raise ValueError(\"No value was passed to the function\")\n\n    is_negative = hex_num[0] == \"-\"\n    if is_negative:\n        hex_num = hex_num[1:]\n\n    try:\n        int_num = int(hex_num, 16)\n    except ValueError:\n        raise ValueError(\"Invalid value was passed to the function\")\n\n    bin_str = \"\"\n    while int_num > 0:\n        bin_str = str(int_num % 2) + bin_str\n        int_num >>= 1\n\n    return int((\"-\" + bin_str) if is_negative else bin_str)\n\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/hex_to_bin.py#L16-L52","documentation":"Raised by hex_to_bin(hex_num) in conversions/hex_to_bin.py:34-38 when the input strips to an empty string. The function expects a hexadecimal string; an empty or whitespace-only string carries no digits to convert, so it raises ValueError('No value was passed to the function') before attempting int(hex_num, 16).","triggerScenarios":"hex_to_bin(''), hex_to_bin('   '), hex_to_bin('-') after sign stripping in caller code, or passing an empty variable read from a file/arg/env.","commonSituations":"Programmatic pipelines where a previous step produced an empty hex field; CLI scripts consuming argv without checking presence; optional config keys defaulting to ''.","solutions":["Guard for blank input before calling: if not hex_str.strip(): skip/handle","Supply a sensible default ('0') when the field is optional","Validate required CLI args early (argparse required=True) so empty values never reach the converter"],"exampleFix":"# before\nhex_to_bin(hex_arg)  # empty argv -> ValueError\n\n# after\nif not hex_arg.strip():\n    raise SystemExit('hex value required')\nprint(hex_to_bin(hex_arg))","handlingStrategy":"validation","validationCode":"if not isinstance(hex_num, str) or not hex_num.strip():\n    raise ValueError('a hexadecimal string is required')","typeGuard":"def is_nonempty_str(v: object) -> TypeGuard[str]:\n    return isinstance(v, str) and bool(v.strip())","tryCatchPattern":null,"preventionTips":["Make hex arguments required in argparse/UI instead of optional-with-empty-default","Filter empty tokens when splitting input lines","Treat blank as '0' explicitly if that is your domain's convention"],"tags":["python","value-error","hex","binary","empty-input"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}