iOfficeAI/OfficeCLI · error · ArgumentException
'src' property for ole type cannot be empty
Error message
'src' property for ole type cannot be empty
What it means
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.
Source
Thrown at src/officecli/Core/OleHelper.cs:605
// ==================== Shared Add helpers ====================
//
// The following methods extract duplicated boilerplate that previously
// appeared verbatim in Word/Excel/PowerPoint AddOle handlers.
/// <summary>
/// Validate and extract the required <c>src</c> (or <c>path</c>) property
/// from the caller-supplied dictionary. Throws
/// <see cref="ArgumentException"/> when neither key is present or the
/// value is blank.
/// </summary>
public static string RequireSource(Dictionary<string, string>? properties)
{
properties ??= new Dictionary<string, string>();
if (!properties.TryGetValue("src", out var srcPath)
&& !properties.TryGetValue("path", out srcPath))
throw new ArgumentException("'src' property is required for ole type");
if (string.IsNullOrWhiteSpace(srcPath))
throw new ArgumentException("'src' property for ole type cannot be empty");
return srcPath;
}
/// <summary>
/// Resolve the ProgID from explicit property → auto-detected from
/// extension, then validate. Replaces the 4-line fallback chain that
/// was duplicated in every handler.
/// </summary>
public static string ResolveProgId(Dictionary<string, string> properties, string srcPath)
{
var progId = properties.GetValueOrDefault("progId")
?? properties.GetValueOrDefault("progid")
?? DetectProgId(srcPath);
ValidateProgId(progId);
return progId;
}
/// <summary>View on GitHub (pinned to 1ced45e900)
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.
Example fix
// before
props["src"] = Environment.GetEnvironmentVariable("OLE_FILE") ?? ""; // empty if unset
AddOle(props); // throws 283
// after
var file = Environment.GetEnvironmentVariable("OLE_FILE")
?? throw new InvalidOperationException("OLE_FILE not set");
props["src"] = file;
AddOle(props); Defensive patterns
Strategy: validation
Validate before calling
var src = props.GetValueOrDefault("src") ?? props.GetValueOrDefault("path");
if (string.IsNullOrWhiteSpace(src))
throw new InvalidOperationException("OLE src is blank"); Type guard
static bool HasNonBlankSource(Dictionary<string,string> p)
=> (p.TryGetValue("src", out var s) || p.TryGetValue("path", out s))
&& !string.IsNullOrWhiteSpace(s); Try / catch
try { RequireSource(props); }
catch (ArgumentException ex) when (ex.Message.Contains("cannot be empty"))
{ /* re-read path from user */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Env-var not exported so interpolation yields empty; a template left src as a placeholder empty string; a JSON config with "src": "".
Related errors
- Invalid display value ''. Expected 'icon' or 'content'.
- Invalid display value '{value}'. Expected 'icon' or 'content
- 'src' property is required for ole type
- Invalid color value: '{original}'. RGB percentage components
- Invalid color value: '{original}'. RGB components must be 0-
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/b578253d9f97da4e.
Report an issue: GitHub.