iOfficeAI/OfficeCLI · error · ArgumentException

Path cannot be empty.

Error message

Path cannot be empty.

What it means

Thrown by ExcelHandler.Get when the path argument is null or empty. Get is the universal read entry point and requires a non-empty path; an empty path has no meaning because even the workbook root is addressed by '/'.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Query.cs:19

// Copyright 2026 OfficeCLI (https://OfficeCLI.AI)
// SPDX-License-Identifier: Apache-2.0

using System.Text.RegularExpressions;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using OfficeCli.Core;
using X14 = DocumentFormat.OpenXml.Office2010.Excel;

namespace OfficeCli.Handlers;

public partial class ExcelHandler
{
    // ==================== Query Layer ====================

    public DocumentNode Get(string path, int depth = 1)
    {
        if (string.IsNullOrEmpty(path))
            throw new ArgumentException("Path cannot be empty.");
        path = NormalizeExcelPath(path);
        path = ResolveSheetIndexInPath(path);
        if (path == "/")
        {
            var node = new DocumentNode { Path = "/", Type = "workbook" };

            // Core document properties
            var props = _doc.PackageProperties;
            if (props.Title != null) node.Format["title"] = props.Title;
            if (props.Creator != null) node.Format["author"] = props.Creator;
            if (props.Subject != null) node.Format["subject"] = props.Subject;
            if (props.Keywords != null) node.Format["keywords"] = props.Keywords;
            if (props.Description != null) node.Format["description"] = props.Description;
            if (props.Category != null) node.Format["category"] = props.Category;
            if (props.LastModifiedBy != null) node.Format["lastModifiedBy"] = props.LastModifiedBy;
            if (props.Revision != null) node.Format["revisionNumber"] = props.Revision;
            if (props.Created != null) node.Format["created"] = props.Created.Value.ToString("o");
            if (props.Modified != null) node.Format["modified"] = props.Modified.Value.ToString("o");

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Pass a concrete path; use '/' to address the workbook root.
  2. In calling code, default the path to '/' when it is null or whitespace.
  3. Validate path presence at the dispatch boundary before invoking Get.

Example fix

// before
var node = excel.Get(path);   // path may be null/empty

// after
if (string.IsNullOrWhiteSpace(path)) path = "/";
var node = excel.Get(path);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(path))
    path = "/";   // or throw at the dispatch boundary
var node = excel.Get(path);

Prevention

When it happens

Trigger: Calling Get(null), Get(""), Get(" ") programmatically, or a CLI/dispatch layer that forwards an unset path variable.

Common situations: A templating layer interpolating an undefined path variable; an MCP/agent tool call with a missing 'path' field; a loop that occasionally yields an empty selector.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/7760b317b3ad5d36. Report an issue: GitHub.