{"record":{"id":"ee15d3e7b458a2b6","repo":"TheAlgorithms/Go","slug":"input-string-is-empty-ee15d3","errorCode":null,"errorMessage":"input string is empty","messagePattern":"input string is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"conversion/hexadecimaltodecimal.go","lineNumber":28,"sourceCode":"// Supported Hexadecimal number range is 0 to 7FFFFFFFFFFFFFFF.\n\npackage conversion\n\nimport (\n\t\"fmt\"\n\t\"regexp\"\n\t\"strings\"\n)\n\nvar isValidHexadecimal = regexp.MustCompile(\"^[0-9A-Fa-f]+$\").MatchString\n\n// hexToDecimal converts a hexadecimal string to a decimal integer.\nfunc hexToDecimal(hexStr string) (int64, error) {\n\n\thexStr = strings.TrimSpace(hexStr)\n\n\tif len(hexStr) == 0 {\n\t\treturn 0, fmt.Errorf(\"input string is empty\")\n\t}\n\n\t// Check if the string has a valid hexadecimal prefix\n\tif len(hexStr) > 2 && (hexStr[:2] == \"0x\" || hexStr[:2] == \"0X\") {\n\t\thexStr = hexStr[2:]\n\t}\n\n\t// Validate the hexadecimal string\n\tif !isValidHexadecimal(hexStr) {\n\t\treturn 0, fmt.Errorf(\"invalid hexadecimal string\")\n\t}\n\n\tvar decimalValue int64\n\tfor _, char := range hexStr {\n\t\tvar digit int64\n\t\tif char >= '0' && char <= '9' {\n\t\t\tdigit = int64(char - '0')\n\t\t} else if char >= 'A' && char <= 'F' {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/conversion/hexadecimaltodecimal.go#L10-L46","documentation":"Returned by hexToDecimal when the input string, after TrimSpace, has zero length; the conversion has no digits to parse, so the empty-input guard rejects it before prefix or format validation runs.","triggerScenarios":"Thrown at conversion/hexadecimaltodecimal.go:28 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the string is non-empty (after TrimSpace) before converting","Return 0 as a default for empty input when semantically acceptable","Prompt the user for a value instead of passing empty strings"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}