{"record":{"id":"b578253d9f97da4e","repo":"iOfficeAI/OfficeCLI","slug":"src-property-for-ole-type-cannot-be-empty","errorCode":null,"errorMessage":"'src' property for ole type cannot be empty","messagePattern":"'src' property for ole type cannot be empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/OleHelper.cs","lineNumber":605,"sourceCode":"    // ==================== Shared Add helpers ====================\n    //\n    // The following methods extract duplicated boilerplate that previously\n    // appeared verbatim in Word/Excel/PowerPoint AddOle handlers.\n\n    /// <summary>\n    /// Validate and extract the required <c>src</c> (or <c>path</c>) property\n    /// from the caller-supplied dictionary. Throws\n    /// <see cref=\"ArgumentException\"/> when neither key is present or the\n    /// value is blank.\n    /// </summary>\n    public static string RequireSource(Dictionary<string, string>? properties)\n    {\n        properties ??= new Dictionary<string, string>();\n        if (!properties.TryGetValue(\"src\", out var srcPath)\n            && !properties.TryGetValue(\"path\", out srcPath))\n            throw new ArgumentException(\"'src' property is required for ole type\");\n        if (string.IsNullOrWhiteSpace(srcPath))\n            throw new ArgumentException(\"'src' property for ole type cannot be empty\");\n        return srcPath;\n    }\n\n    /// <summary>\n    /// Resolve the ProgID from explicit property → auto-detected from\n    /// extension, then validate. Replaces the 4-line fallback chain that\n    /// was duplicated in every handler.\n    /// </summary>\n    public static string ResolveProgId(Dictionary<string, string> properties, string srcPath)\n    {\n        var progId = properties.GetValueOrDefault(\"progId\")\n            ?? properties.GetValueOrDefault(\"progid\")\n            ?? DetectProgId(srcPath);\n        ValidateProgId(progId);\n        return progId;\n    }\n\n    /// <summary>","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/OleHelper.cs#L587-L623","documentation":"Thrown by RequireSource when 'src' (or 'path') is present but blank (empty or whitespace-only). The key existing is not enough — it must carry a usable file path. This catches config typos like src=\"\" that would otherwise produce a confusing downstream file-not-found.","triggerScenarios":"Passing src=\"\" or src=\"   \"; setting src from an environment variable that is unset (expanding to empty); trailing-only whitespace from a malformed CSV/config field.","commonSituations":"Env-var not exported so interpolation yields empty; a template left src as a placeholder empty string; a JSON config with \"src\": \"\".","solutions":["Provide a real, non-empty file path for src/path.","Guard before the call: if (string.IsNullOrWhiteSpace(filePath)) { report and abort; }.","Validate the source variable is set at script startup, not only at the Add call."],"exampleFix":"// before\nprops[\"src\"] = Environment.GetEnvironmentVariable(\"OLE_FILE\") ?? \"\"; // empty if unset\nAddOle(props); // throws 283\n\n// after\nvar file = Environment.GetEnvironmentVariable(\"OLE_FILE\")\n    ?? throw new InvalidOperationException(\"OLE_FILE not set\");\nprops[\"src\"] = file;\nAddOle(props);","handlingStrategy":"validation","validationCode":"var src = props.GetValueOrDefault(\"src\") ?? props.GetValueOrDefault(\"path\");\nif (string.IsNullOrWhiteSpace(src))\n    throw new InvalidOperationException(\"OLE src is blank\");","typeGuard":"static bool HasNonBlankSource(Dictionary<string,string> p)\n    => (p.TryGetValue(\"src\", out var s) || p.TryGetValue(\"path\", out s))\n       && !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { RequireSource(props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"cannot be empty\"))\n{ /* re-read path from user */ }","preventionTips":["Validate the file path variable is non-empty at startup.","Trim and check env vars before assigning them to src.","Never leave src as an empty placeholder string."],"tags":["ole","validation","argument","office","empty-value"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}