iOfficeAI/OfficeCLI · error · Core.CliException
not_found
not_found
Error message
No elements matched selector: {path} What it means
Thrown (code not_found) by the selector branch of Remove when FilterSelector(path, ...) returns zero targets. This branch handles selector paths (not starting with '/') and content-filter paths; an empty match set is reported as not_found rather than a silent no-op, mirroring the Set dispatch so query/set/remove agree on selector behavior.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Remove.cs:49
// each match, mirroring ExcelHandler.Set's selector branch. Row removals
// are TRUE shift-deletes (rows below shift up — see "row[N] — true shift
// delete"), so multiple matched rows MUST be removed in DESCENDING row
// order: deleting /Sheet/row[2] first renumbers the old row[4] to row[3]
// and the next delete would hit the wrong row. Non-row targets carry
// index 0 and keep a stable relative order.
if (!string.IsNullOrEmpty(path)
&& (!path.StartsWith("/") || Core.AttributeFilter.IsContentFilterPath(path)))
{
// Narrow via the shared engine (same as Set / query): pure-AND on the
// legacy path, `or` selectors queried bracket-stripped then narrowed by
// the boolean expression tree. The IsContentFilterPath arm routes a
// `/`-scoped content filter (`/Sheet1/cell[value>5 or value<1]`) here
// too, matching the Set dispatch — query, set and remove now agree on
// every selector shape.
var (targets, _) = Core.AttributeFilter.FilterSelector(path, Query, ResolveCellAttributeAlias);
if (targets.Count == 0)
// Empty selector result is not_found, not a crash — see Set.cs.
throw new Core.CliException($"No elements matched selector: {path}") { Code = "not_found" };
var ordered = targets.OrderByDescending(t => ExtractRowIndexForRemoval(t.Path)).ToList();
string? lastWarning = null;
foreach (var target in ordered)
{
var w = Remove(target.Path, properties);
if (w != null) lastWarning = w;
}
var summary = $"{ordered.Count} element(s) removed by selector '{path}'";
return lastWarning != null ? $"{summary}; {lastWarning}" : summary;
}
path = NormalizeExcelPath(path);
path = ResolveSheetIndexInPath(path);
var segments = path.TrimStart('/').Split('/', 2);
var sheetName = segments[0];
// Handle /namedrange[N] or /namedrange[Name] before sheet lookupView on GitHub (pinned to 1ced45e900)
Solutions
- Run the same selector as a get/query first to confirm it matches before calling remove.
- Correct the selector (column name, value, operator) against the actual sheet contents.
- Treat not_found as benign in your caller if an empty match is acceptable (catch code 'not_found').
Example fix
// before remove row[col.mising=foo] // typo: 'mising' // after get row[col.missing=foo] // verify matches exist remove row[col.missing=foo]
Defensive patterns
Strategy: try-catch
Validate before calling
# dry-run the selector as a query first
matches = doc.query('row[col.missing=foo]')
if not matches:
print('selector matches nothing — nothing to remove')
else:
doc.remove('row[col.missing=foo]') Type guard
null
Try / catch
try:
doc.remove('row[col.missing=foo]')
except officecli.OfficeCliError as e:
if getattr(e, 'code', None) == 'not_found' or 'No elements matched' in str(e):
pass # empty match is benign for our use case
else:
raise Prevention
- Run the selector as a query first to confirm matches before removing.
- Verify column names and values against the actual sheet.
- Treat 'not_found' as benign if an empty match is acceptable.
When it happens
Trigger: remove row[col.missing=foo] where no rows match; remove /Sheet1/cell[value>999] with no such cells; any selector that matches nothing.
Common situations: Filtering on a non-existent column/value; race where data changed between query and remove; case mismatch in values; selector typos.
Related errors
- invalid_selector
- invalid_value
- Sheet not found: {cmtSheetName}
- Sheet not found: {dvSheetName}
- Sheet not found: {afSheetName}
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/5bf4a5fe6fc5eb67.
Report an issue: GitHub.