{"record":{"id":"630f8c7822f49b60","repo":"iOfficeAI/OfficeCLI","slug":"src-property-is-required-for-ole-type","errorCode":null,"errorMessage":"'src' property is required for ole type","messagePattern":"'src' property is required for ole type","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/OleHelper.cs","lineNumber":603,"sourceCode":"    }\n\n    // ==================== 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    }","sourceCodeStart":585,"sourceCodeEnd":621,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/OleHelper.cs#L585-L621","documentation":"Thrown by RequireSource when neither the 'src' nor the 'path' key exists in the OLE property dictionary. An OLE object must reference an embedded file, so a missing source is a hard error rather than a no-op. Both 'src' and 'path' are accepted as aliases for the same field.","triggerScenarios":"Building a properties dictionary for an OLE Add but forgetting to include the file path; using a wrong key name like 'source' or 'file'.","commonSituations":"Renaming keys during a refactor and missing the OLE path; reading path from a variable that was null so the key never got added; copy-paste from a non-OLE shape spec that uses different keys.","solutions":["Add properties[\"src\"] = filePath (or \"path\") before the Add call.","Verify the key spelling — only 'src' and 'path' are recognized.","If the path comes from user input, validate it is non-null before adding the key."],"exampleFix":"// before\nvar props = new Dictionary<string,string> { [\"display\"] = \"icon\" };\nAddOle(props); // throws 282 — no src/path\n\n// after\nvar props = new Dictionary<string,string>\n{\n    [\"src\"] = filePath,\n    [\"display\"] = \"icon\"\n};\nAddOle(props);","handlingStrategy":"validation","validationCode":"if (!props.ContainsKey(\"src\") && !props.ContainsKey(\"path\"))\n    throw new InvalidOperationException(\"OLE object needs a src/path\");","typeGuard":"static bool HasOleSource(Dictionary<string,string> p)\n    => p.ContainsKey(\"src\") || p.ContainsKey(\"path\");","tryCatchPattern":"try { RequireSource(props); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"required\"))\n{ /* prompt user for file path */ }","preventionTips":["Use a helper that always sets src from a validated path variable.","Fail fast at script start if the source file variable is unset.","Keep key names consistent ('src'/'path' only)."],"tags":["ole","validation","argument","office","missing-property"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}