{"record":{"id":"f2023034b6b01fdb","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"failed-to-parse-the-input","errorCode":null,"errorMessage":"Failed to parse the input","messagePattern":"Failed to parse the input","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/Tools/GuidTools.cs","lineNumber":43,"sourceCode":"            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            try\n            {\n                var braceIndex = source.IndexOfAny(new[] {'{', '('});\n                if (braceIndex >= 0)\n                {\n                    var endingBraceIndex = source.IndexOfAny(new[] {'}', ')'});\n                    if (endingBraceIndex < 0)\n                        throw new ArgumentException(\"Invalid brace format\");\n\n                    source = source.Substring(braceIndex, endingBraceIndex - braceIndex + 1);\n                }\n                return new Guid(source);\n            }\n            catch (Exception ex)\n            {\n                throw new ArgumentException(\"Failed to parse the input\", ex);\n            }\n            //throw new NotImplementedException();\n        }\n\n        /// <summary>\n        /// Try to parse the supplied string into a guid. Faster than catching exceptions.\n        /// </summary>\n        public static bool GuidTryParse(string s, out Guid result)\n        {\n            result = Guid.Empty;\n            if (string.IsNullOrEmpty(s) || !GuidMatchRegex.IsMatch(s))\n            {\n                return false;\n            }\n            result = new Guid(s);\n            return true;\n        }\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/Tools/GuidTools.cs#L25-L61","documentation":"Thrown by the GuidTools parse method (the catch-all wrapping new Guid(source)). The method first extracts content inside braces/parens; if the trimmed string still cannot be parsed by the Guid constructor (which throws FormatException for bad GUID strings), it is rethrown wrapped as ArgumentException(\"Failed to parse the input\", ex). The inner exception preserves the original parse error.","triggerScenarios":"Passing a string that is not a valid GUID in any accepted form (N/D/B/P formats), e.g. \"xyz\", \"12345\", or a GUID with non-hex characters / wrong segment lengths, even after brace stripping.","commonSituations":"Parsing user-entered IDs, reading GUIDs from config/CSV where columns are misaligned, clipboard text with stray whitespace/punctuation, or a value extracted from inside braces that is still malformed.","solutions":["Pre-validate with GuidTools.GuidTryParse(s, out var g) (mentioned right below in the same file) and avoid the exception path entirely.","Sanitise the input: trim whitespace and confirm it matches the standard 8-4-4-4-12 hex pattern before parsing.","If you read from a data source, log the raw string on failure (from ex.InnerException) to locate the bad row."],"exampleFix":"// before\nvar g = GuidTools.ParseGuid(input); // throws on bad input\n\n// after\nif (GuidTools.GuidTryParse(input, out var g))\n    Use(g);\nelse\n    logger.Warn($\"Ignoring malformed GUID: {input}\");","handlingStrategy":"validation","validationCode":"if (!GuidTools.GuidTryParse(input, out var g))\n    return; // or surface a user-facing error\n// use g","typeGuard":"static bool IsValidGuid(string s)\n    => !string.IsNullOrEmpty(s) && GuidTools.GuidTryParse(s, out _);","tryCatchPattern":"try { return GuidTools.ParseGuid(input); }\ncatch (ArgumentException ex) { logger.Warn($\"Bad GUID '{input}': {ex.InnerException?.Message}\"); return Guid.Empty; }","preventionTips":["Always prefer GuidTryParse over the throwing parse for external input.","Trim and brace-strip input consistently before validation.","Log the original string from the inner exception when parse fails in batch jobs."],"tags":["parsing","guid","validation","csharp","kloctools"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}