fix(explore): handle single -F flag as array to prevent TypeError#1218
fix(explore): handle single -F flag as array to prevent TypeError#1218sentry[bot] wants to merge 1 commit into
Conversation
|
| let fieldList = [...defaultFieldsForDataset(dataset)]; | ||
| if (userSuppliedFields) { | ||
| fieldList = flags.field; | ||
| fieldList = Array.isArray(flags.field) ? flags.field : [flags.field]; |
There was a problem hiding this comment.
Single -F flag still causes TypeError in appendFieldHints via appendFlagHints
The fix normalizes flags.field into fieldList but leaves the raw flags.field string un-normalized. appendFlagHints is called with hintFlags = { ...flags, dataset }, so hintFlags.field remains the bare string, which is passed to appendFieldHints. There the string reaches fields.filter(...) (when --metric is active) or fieldList.join(",") (the common non-metric case) — both throw TypeError because strings lack those array methods, reproducing the same crash the PR set out to fix.
Evidence
flags.fieldis typedstring[] | undefinedbut the CLI parser emits astringfor a single-Fflag (the PR's root cause).- The fix at line 716 coerces
flags.fieldinto a localfieldList, but never mutates or re-bindsflags.fielditself. hintFlags = { ...flags, dataset }(line ~803) spreads the originalflags, sohintFlags.fieldstays the raw string.- Both
prevHint/nextHintare evaluated eagerly as arguments topaginationHint, soappendFlagHintsruns on every invocation regardless of pagination state. - In
appendFieldHints,const fields = rawFields ?? []keeps the string; non-metric path hitsfieldList.join(",")and metric path hitsfields.filter(...), both throwing on a string.
Identified by Warden find-bugs · PQ4-HKP
| let fieldList = [...defaultFieldsForDataset(dataset)]; | ||
| if (userSuppliedFields) { | ||
| fieldList = flags.field; | ||
| fieldList = Array.isArray(flags.field) ? flags.field : [flags.field]; |
There was a problem hiding this comment.
Bug: The appendFieldHints function crashes with a TypeError because it receives a string for flags.field when a single -F flag is used.
Severity: HIGH
Suggested Fix
Ensure that flags.field is always an array before it is used by the hint generation functions. Similar to how fieldList is created, the flags.field property on the hintFlags object should be normalized to an array if it is a string. This will prevent the TypeError when .filter() is called within appendFieldHints.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: src/commands/explore.ts#L716
Potential issue: When a user provides a single `-F` flag to the `explore` command, the
CLI parser sets `flags.field` to a string. While the main query logic correctly handles
this by converting it to an array, the pagination hint generation logic does not. It
uses a shallow copy of the original `flags` object, passing the string value of
`flags.field` to the `appendFlagHints` function, and subsequently to `appendFieldHints`.
The `appendFieldHints` function expects an array and attempts to call `.filter()` on the
string, which results in a `TypeError` and causes the command to crash after a
successful query.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 487dba7. Configure here.
| let fieldList = [...defaultFieldsForDataset(dataset)]; | ||
| if (userSuppliedFields) { | ||
| fieldList = flags.field; | ||
| fieldList = Array.isArray(flags.field) ? flags.field : [flags.field]; |
There was a problem hiding this comment.
Incomplete field array coercion
High Severity
The single -F coercion only updates fieldList, while pagination hint building still passes the raw flags.field into appendFieldHints. With one -F, that value remains a string, so .join or .filter still throws after the query succeeds and the command never returns results.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 487dba7. Configure here.
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 5318 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 81.83% 81.88% +0.05%
==========================================
Files 423 423 —
Lines 29343 29343 —
Branches 19117 19119 +2
==========================================
+ Hits 24009 24025 +16
- Misses 5334 5318 -16
- Partials 1988 1995 +7Generated by Codecov Action |


This PR addresses CLI-28C, a TypeError occurring in the
explorecommand.Root Cause:
The
flags.fieldargument insrc/commands/explore.tsis defined asvariadic: true. However, when a user supplies only a single-Fflag, the CLI parser assigns a string toflags.fieldinstead of a single-element array. The command function then blindly assignsfieldList = flags.field, makingfieldLista string. Subsequent calls to.find()onfieldList(e.g., inresolveDatasetConfigorfindFirstAggregate) then fail withTypeError: e.find is not a functionbecause strings do not have a.find()method.Fix:
To resolve this,
flags.fieldis now explicitly coerced to an array before being assigned tofieldList. This ensures thatfieldListis always an array, regardless of whether one or multiple-Fflags were provided, thus preventing the TypeError.Fixes CLI-28C
Comment
@sentry <feedback>on this PR to have Autofix iterate on the changes.