{"record":{"id":"ea9aaf1c413c4f53","repo":"iOfficeAI/OfficeCLI","slug":"image-source-cannot-be-empty","errorCode":null,"errorMessage":"Image source cannot be empty","messagePattern":"Image source cannot be empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/ImageSource.cs","lineNumber":30,"sourceCode":"/// Resolves image sources from file paths, data URIs, or HTTP(S) URLs into a stream and content type.\n/// Supports:\n///   - Local file path: \"/tmp/logo.png\", \"C:\\images\\photo.jpg\"\n///   - Data URI: \"data:image/png;base64,iVBOR...\"\n///   - HTTP(S) URL: \"https://example.com/image.png\"\n///\n/// Returns a content type string compatible with OpenXmlPart.AddImagePart() (e.g. ImagePartType.Png).\n/// </summary>\ninternal static class ImageSource\n{\n    /// <summary>\n    /// Resolve an image source string into a stream and content type string.\n    /// Caller is responsible for disposing the returned stream.\n    /// The returned contentType can be passed directly to AddImagePart().\n    /// </summary>\n    public static (Stream Stream, PartTypeInfo ContentType) Resolve(string source)\n    {\n        if (string.IsNullOrWhiteSpace(source))\n            throw new ArgumentException(\"Image source cannot be empty\");\n\n        // Data URI: data:image/png;base64,iVBOR...\n        if (source.StartsWith(\"data:\", StringComparison.OrdinalIgnoreCase))\n            return ResolveDataUri(source);\n\n        // HTTP(S) URL\n        if (source.StartsWith(\"http://\", StringComparison.OrdinalIgnoreCase) ||\n            source.StartsWith(\"https://\", StringComparison.OrdinalIgnoreCase))\n            return ResolveUrl(source);\n\n        // Local file path\n        return ResolveFile(source);\n    }\n\n    /// <summary>\n    /// Determine content type string from a file extension (with or without dot).\n    /// Returns a value usable with AddImagePart().\n    /// </summary>","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/ImageSource.cs#L12-L48","documentation":"Thrown by ImageSource.Resolve when the source string is null, empty, or whitespace-only. This is the entry point for all image resolution (file path, data URI, or HTTP URL), and it refuses to proceed with a blank source because the downstream resolvers would produce confusing errors about missing schemes or file-not-found for an empty string.","triggerScenarios":"Calling ImageSource.Resolve(null), ImageSource.Resolve(\"\"), or ImageSource.Resolve(\"   \"). This happens when an Add image/picture/ole command receives a missing or blank 'src'/'icon'/'preview' property, or when a programmatic caller passes an uninitialized string variable.","commonSituations":"An agent that constructs an image-add command from a template but forgets to fill in the source field. A batch script where a variable expansion produced an empty string. A data URI that was truncated to just 'data:' or an empty string during serialization.","solutions":["Provide a non-empty image source: a local file path, an http(s) URL, or a data URI.","Check that the 'src' (or 'icon'/'preview') property in your Add command dictionary is populated before invoking the handler.","If the source comes from a variable, add a null/empty guard upstream and skip the operation or prompt for a valid source."],"exampleFix":"// before — blank source throws\nadd image src='' path='/body'\n\n// after — provide a real source\nadd image src='/tmp/logo.png' path='/body'","handlingStrategy":"validation","validationCode":"// Validate source is non-empty before resolving\nif (string.IsNullOrWhiteSpace(imageSource))\n{\n    Console.Error.WriteLine(\"Image source is required and cannot be empty.\");\n    return;\n}\nvar (stream, contentType) = ImageSource.Resolve(imageSource);","typeGuard":null,"tryCatchPattern":"try\n{\n    var (stream, contentType) = ImageSource.Resolve(source);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"cannot be empty\"))\n{\n    // Skip this image or prompt for a valid source\n}","preventionTips":["Always check that the 'src', 'icon', or 'preview' property is populated before calling Add image/ole.","Use a guard clause: if (string.IsNullOrWhiteSpace(src)) return early or throw your own descriptive error.","Validate command dictionaries for required keys before passing them to the handler."],"tags":["image","argument-validation","empty-value","add-command"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}