iOfficeAI/OfficeCLI · error · ArgumentException
File source cannot be empty
Error message
File source cannot be empty
What it means
Thrown by FileSource.Resolve when the source string is null, empty, or whitespace. Resolve dispatches by prefix (data:, http(s)://, else filesystem), so an empty source has no resolvable target and is rejected up front.
Source
Thrown at src/officecli/Core/FileSource.cs:26
/// Unified counterpart to <see cref="ImageSource"/> for non-image binary files (media, 3D models, CSV, etc.).
///
/// Supports:
/// - Local file path: "/tmp/model.glb", "C:\media\video.mp4"
/// - HTTP(S) URL: "https://example.com/video.mp4"
/// - Data URI: "data:video/mp4;base64,AAAA..."
///
/// Returns a MemoryStream (always seekable) and the detected file extension.
/// </summary>
internal static class FileSource
{
/// <summary>
/// Resolve a source string into a seekable MemoryStream and file extension (with dot, e.g. ".glb").
/// Caller is responsible for disposing the returned stream.
/// </summary>
public static (MemoryStream Stream, string Extension) Resolve(string source)
{
if (string.IsNullOrWhiteSpace(source))
throw new ArgumentException("File source cannot be empty");
if (source.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
return ResolveDataUri(source);
if (source.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
source.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
return ResolveUrl(source);
return ResolveFile(source);
}
/// <summary>
/// Check whether a string looks like a resolvable source (URL, data URI, or existing local file).
/// Useful for distinguishing file/URL sources from inline data (e.g. CSV inline vs file path).
/// </summary>
public static bool IsResolvable(string source)
{
if (string.IsNullOrWhiteSpace(source)) return false;View on GitHub (pinned to 1ced45e900)
Solutions
- Provide a non-empty source: a filesystem path, an http(s):// URL, or a data: URI.
- If the source is optional, skip the call entirely rather than passing an empty string.
- Validate the input is non-blank before invoking the API.
Example fix
// before
var (stream, ext) = FileSource.Resolve(userInput); // userInput may be ""
// after
if (string.IsNullOrWhiteSpace(userInput))
throw new InvalidOperationException("source is required");
var (stream, ext) = FileSource.Resolve(userInput); Defensive patterns
Strategy: validation
Validate before calling
static (MemoryStream, string) SafeResolve(string source)
{
if (string.IsNullOrWhiteSpace(source))
throw new InvalidOperationException("A non-empty source (path/URL/data URI) is required.");
return FileSource.Resolve(source);
} Type guard
static bool IsResolvableSource(string s) => !string.IsNullOrWhiteSpace(s);
Try / catch
try { var r = FileSource.Resolve(src); }
catch (ArgumentException ex) when (ex.Message == "File source cannot be empty")
{ /* prompt user / skip */ } Prevention
- Treat blank source as 'omitted' rather than passing empty string.
- Validate config-supplied sources at load time.
When it happens
Trigger: Calling FileSource.Resolve (or a higher-level API that takes a data=/model3d=/media= source) with an empty/null/whitespace string. The guard runs before any prefix dispatch.
Common situations: A config field left blank; a template variable that resolved to empty; an optional parameter passed as empty string instead of omitted; user input not validated.
Related errors
- Invalid data URI: missing comma separator
- Only base64-encoded data URIs are supported
- pivot name must not be empty
- invalid sort: '{mode}'. Valid: asc, desc, locale, locale-des
- Invalid subtotals '{s}'. Valid: on, off (default on)
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/53f49315a7ccd9d2.
Report an issue: GitHub.