{"record":{"id":"c5053df6813a1c39","repo":"babalae/better-genshin-impact","slug":"error-c5053d","errorCode":null,"errorMessage":"文件路径不能为空","messagePattern":"文件路径不能为空","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Core/Script/Utils/ScriptUtils.cs","lineNumber":16,"sourceCode":"﻿using System;\nusing System.IO;\nusing System.Linq;\n\nnamespace BetterGenshinImpact.Core.Script.Utils;\n\npublic class ScriptUtils\n{\n    /// <summary>\n    /// Normalize and validate a path.\n    /// </summary>\n    public static string NormalizePath(string root, string path)\n    {\n        // 校验空字符串\n        if (string.IsNullOrWhiteSpace(path))\n            throw new ArgumentException(\"文件路径不能为空\");\n\n        // 检查是否含有非法文件名字符\n        var invalidChars = Path.GetInvalidFileNameChars();\n        string fileName = Path.GetFileName(path);\n        if (fileName.Any(c => invalidChars.Contains(c)))\n        {\n            throw new ArgumentException($\"文件路径 '{path}' 包含非法字符\");\n        }\n\n        // 替换分隔符\n        path = path.Replace('\\\\', '/');\n\n        // 组合并获取绝对路径\n        var fullPath = Path.GetFullPath(Path.Combine(root, path));\n\n        // 防止越界访问\n        if (!fullPath.StartsWith(root, StringComparison.OrdinalIgnoreCase))\n        {","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Utils/ScriptUtils.cs#L1-L34","documentation":"Thrown by ScriptUtils.NormalizePath when the input path is null, empty, or whitespace. This is the first validation gate before any path normalization/escape check; it rejects obviously invalid input early.","triggerScenarios":"NormalizePath(root, path) called with path = null, \"\", or a string of only whitespace. Any caller (manifest parsing, file checkout, webview bridge) passing an unvalidated path triggers it.","commonSituations":"A manifest field for a script path is empty; a JSON config omits the path key and deserialization yields null/empty; a webview request supplies no path parameter.","solutions":["Validate at the source: if path comes from JSON/config, use a required-field check or [JsonRequired] so the error surfaces at deserialization, not deep in NormalizePath.","Coalesce empty to a sensible default if an empty path is semantically valid for the caller.","Keep this throw but ensure all callers catch ArgumentException and present a user-facing message naming the missing field."],"exampleFix":"// before\nif (string.IsNullOrWhiteSpace(path))\n    throw new ArgumentException(\"文件路径不能为空\");\n\n// after (include parameter name)\nif (string.IsNullOrWhiteSpace(path))\n    throw new ArgumentException(\"文件路径不能为空\", nameof(path));","handlingStrategy":"validation","validationCode":"// Validate at the source (e.g., JSON config) before calling NormalizePath\nif (string.IsNullOrWhiteSpace(manifest.Path))\n    throw new ArgumentException(\"manifest 缺少 path 字段\");","typeGuard":"static bool IsValidPathInput(string? path) =>\n    !string.IsNullOrWhiteSpace(path);","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"不能为空\"))\n{\n    Toast.Error($\"脚本路径为空，请检查 manifest: {scriptName}\");\n}","preventionTips":["Mark manifest path fields as required at deserialization ([JsonRequired]).","Coalesce empty to a default where semantically valid.","Include nameof(path) in the ArgumentException."],"tags":["validation","path","argument","security"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}