{"record":{"id":"53f49315a7ccd9d2","repo":"iOfficeAI/OfficeCLI","slug":"file-source-cannot-be-empty","errorCode":null,"errorMessage":"File source cannot be empty","messagePattern":"File source cannot be empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/FileSource.cs","lineNumber":26,"sourceCode":"/// Unified counterpart to <see cref=\"ImageSource\"/> for non-image binary files (media, 3D models, CSV, etc.).\n///\n/// Supports:\n///   - Local file path: \"/tmp/model.glb\", \"C:\\media\\video.mp4\"\n///   - HTTP(S) URL: \"https://example.com/video.mp4\"\n///   - Data URI: \"data:video/mp4;base64,AAAA...\"\n///\n/// Returns a MemoryStream (always seekable) and the detected file extension.\n/// </summary>\ninternal static class FileSource\n{\n    /// <summary>\n    /// Resolve a source string into a seekable MemoryStream and file extension (with dot, e.g. \".glb\").\n    /// Caller is responsible for disposing the returned stream.\n    /// </summary>\n    public static (MemoryStream Stream, string Extension) Resolve(string source)\n    {\n        if (string.IsNullOrWhiteSpace(source))\n            throw new ArgumentException(\"File source cannot be empty\");\n\n        if (source.StartsWith(\"data:\", StringComparison.OrdinalIgnoreCase))\n            return ResolveDataUri(source);\n\n        if (source.StartsWith(\"http://\", StringComparison.OrdinalIgnoreCase) ||\n            source.StartsWith(\"https://\", StringComparison.OrdinalIgnoreCase))\n            return ResolveUrl(source);\n\n        return ResolveFile(source);\n    }\n\n    /// <summary>\n    /// Check whether a string looks like a resolvable source (URL, data URI, or existing local file).\n    /// Useful for distinguishing file/URL sources from inline data (e.g. CSV inline vs file path).\n    /// </summary>\n    public static bool IsResolvable(string source)\n    {\n        if (string.IsNullOrWhiteSpace(source)) return false;","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/FileSource.cs#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar (stream, ext) = FileSource.Resolve(userInput); // userInput may be \"\"\n// after\nif (string.IsNullOrWhiteSpace(userInput))\n    throw new InvalidOperationException(\"source is required\");\nvar (stream, ext) = FileSource.Resolve(userInput);","handlingStrategy":"validation","validationCode":"static (MemoryStream, string) SafeResolve(string source)\n{\n    if (string.IsNullOrWhiteSpace(source))\n        throw new InvalidOperationException(\"A non-empty source (path/URL/data URI) is required.\");\n    return FileSource.Resolve(source);\n}","typeGuard":"static bool IsResolvableSource(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { var r = FileSource.Resolve(src); }\ncatch (ArgumentException ex) when (ex.Message == \"File source cannot be empty\")\n{ /* prompt user / skip */ }","preventionTips":["Treat blank source as 'omitted' rather than passing empty string.","Validate config-supplied sources at load time."],"tags":["file-source","validation","input-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}