{"record":{"id":"93c8c909f8fff6a5","repo":"studyzy/imewlconverter","slug":"error-93c8c9","errorCode":null,"errorMessage":"文件路径不能为空","messagePattern":"文件路径不能为空","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImeWlConverter.Core/Helpers/FileOperationHelper.cs","lineNumber":113,"sourceCode":"            sw.WriteLine(line);\n            return true;\n        }\n        catch\n        {\n            return false;\n        }\n    }\n\n    public static StreamWriter GetWriteFileStream(string path, Encoding coding)\n    {\n        return new StreamWriter(path, false, coding);\n    }\n\n    public static Encoding GetEncodingType(string fileName)\n    {\n        if (string.IsNullOrWhiteSpace(fileName))\n        {\n            throw new ArgumentException(\"文件路径不能为空\", nameof(fileName));\n        }\n\n        if (!File.Exists(fileName))\n        {\n            throw new FileNotFoundException($\"文件不存在: {fileName}\");\n        }\n\n        try\n        {\n            var result = CharsetDetector.DetectFromFile(fileName);\n            var resultDetected = result?.Detected;\n\n            if (resultDetected == null || resultDetected.Confidence < 0.7)\n            {\n                try\n                {\n                    return Encoding.GetEncoding(\"GB18030\");\n                }","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/studyzy/imewlconverter/blob/16744a12ed5064896cf39095163e44b367aaada1/src/ImeWlConverter.Core/Helpers/FileOperationHelper.cs#L95-L131","documentation":"FileOperationHelper.GetEncodingType auto-detects a file's text encoding via UtfUnknown. It throws ArgumentException (with paramName=fileName) when the path argument is null or whitespace — a standard input precondition on the public method.","triggerScenarios":"Calling GetEncodingType(null), GetEncodingType(\"\"), or GetEncodingType(\"   \"); or when a GUI/CLI field bound to a file path is submitted empty.","commonSituations":"GUI input-file text box left blank but conversion triggered; CLI invoked with an empty -i/--if argument; a glob/wildcard that resolved to an empty path string.","solutions":["Validate the path is non-empty at the CLI/GUI trust boundary before calling GetEncodingType.","If empty/missing files should be tolerated, call ReadFile(path) which returns \"\" instead of throwing.","Bind the input field to a required-field validator so submission is blocked when empty."],"exampleFix":"// before\nvar enc = FileOperationHelper.GetEncodingType(path);\n// after\nif (string.IsNullOrWhiteSpace(path))\n    throw new ArgumentException(\"path required\", nameof(path));\nvar enc = FileOperationHelper.GetEncodingType(path);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(fileName))\n    throw new ArgumentException(\"path required\", nameof(fileName));","typeGuard":null,"tryCatchPattern":"try { var enc = FileOperationHelper.GetEncodingType(path); }\ncatch (ArgumentException) { /* empty path, abort or prompt */ }","preventionTips":["Validate file paths at the trust boundary (CLI argument parsing / GUI submit).","Bind input-file fields to required-field validators that block submission when empty.","If missing files are non-fatal, prefer ReadFile(path) which returns \"\" instead of throwing."],"tags":["file","encoding","argument","validation"],"backgroundTag":null,"analyzedSha":"16744a12ed5064896cf39095163e44b367aaada1","analyzedAt":"2026-08-13T19:53:09.031Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}