{"record":{"id":"54d101de510a5f5d","repo":"TheAlgorithms/Go","slug":"invalid-roman-numeral","errorCode":null,"errorMessage":"invalid roman numeral","messagePattern":"invalid roman numeral","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"conversion/romantoint.go","lineNumber":56,"sourceCode":"\n// RomanToInt converts a roman numeral string to an integer. Roman numerals for numbers\n// outside the range 1 to 3,999 will return an error. Nil or empty string return 0\n// with no error thrown.\nfunc RomanToInt(input string) (int, error) {\n\tif input == \"\" {\n\t\treturn 0, nil\n\t}\n\tvar output int\n\tfor _, n := range nums {\n\t\tfor strings.HasPrefix(input, n.sym) {\n\t\t\toutput += n.val\n\t\t\tinput = input[len(n.sym):]\n\t\t}\n\t}\n\t// if we are still left with input string values then the\n\t// input was invalid and an error is returned.\n\tif len(input) > 0 {\n\t\treturn 0, errors.New(\"invalid roman numeral\")\n\t}\n\treturn output, nil\n}\n","sourceCodeStart":38,"sourceCodeEnd":60,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/conversion/romantoint.go#L38-L60","documentation":"RomanToInt consumes the input by repeatedly stripping known numeral prefixes (CM, M, CD...). If characters remain after all prefixes are tried, the string used symbols that don't form a valid roman numeral (e.g. 'IIII' isn't matched only in some cases, or garbage like 'XYZ').","triggerScenarios":"Thrown at conversion/romantoint.go:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Validate/normalize the roman numeral string before calling RomanToInt","Trim whitespace and ensure uppercase letters only","Report the malformed input to the user with the offending string"],"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"}