[PR #7394] Add Array.isArray check before .join() #12388

Closed
opened 2026-02-16 18:17:18 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7394

State: closed
Merged: No


Both changes are applied. The fix adds defensive type checking in the format function to handle cases where the answer might be a string instead of an array. This can happen when loading older sessions or if data gets stored in an unexpected format.

Summary of the fix:

The bug occurred because props.metadata.answers?.[i()] could sometimes be a string instead of an array (string[]), causing answer.join(", ") to fail since strings don't have a join method.

The fix adds a type check before calling .join():

  1. If answer is falsy or empty, return the fallback text
  2. If answer is not an array, convert it to a string with String(answer)
  3. Otherwise, call .join(", ") as before

This makes the code resilient to data type variations that might occur when loading historical sessions.

Closes #7392

New%20session%20-%202026-01-09T00%3A15%3A38.209Z
opencode session  |  github run

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7394 **State:** closed **Merged:** No --- Both changes are applied. The fix adds defensive type checking in the `format` function to handle cases where the answer might be a string instead of an array. This can happen when loading older sessions or if data gets stored in an unexpected format. **Summary of the fix:** The bug occurred because `props.metadata.answers?.[i()]` could sometimes be a string instead of an array (`string[]`), causing `answer.join(", ")` to fail since strings don't have a `join` method. The fix adds a type check before calling `.join()`: 1. If `answer` is falsy or empty, return the fallback text 2. If `answer` is not an array, convert it to a string with `String(answer)` 3. Otherwise, call `.join(", ")` as before This makes the code resilient to data type variations that might occur when loading historical sessions. Closes #7392 <a href="https://opencode.ai/s/o6hJzKLt"><img width="200" alt="New%20session%20-%202026-01-09T00%3A15%3A38.209Z" src="https://social-cards.sst.dev/opencode-share/TmV3IHNlc3Npb24gLSAyMDI2LTAxLTA5VDAwOjE1OjM4LjIwOVo=.png?model=opencode/claude-opus-4-5&version=1.1.7&id=o6hJzKLt" /></a> [opencode session](https://opencode.ai/s/o6hJzKLt)&nbsp;&nbsp;|&nbsp;&nbsp;[github run](/anomalyco/opencode/actions/runs/20836473607)
yindo added the pull-request label 2026-02-16 18:17:18 -05:00
yindo closed this issue 2026-02-16 18:17:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12388