Skip to content

Comments

fix(locale): prevent titlecase crash on missing session values#604

Open
Olusammytee wants to merge 1 commit intoKilo-Org:devfrom
Olusammytee:fix/310-titlecase-undefined
Open

fix(locale): prevent titlecase crash on missing session values#604
Olusammytee wants to merge 1 commit intoKilo-Org:devfrom
Olusammytee:fix/310-titlecase-undefined

Conversation

@Olusammytee
Copy link
Contributor

Summary

  • make Locale.titlecase safely handle undefined and
    ull values
  • return an empty string for missing input instead of throwing at
    eplace
  • prevent session loading/rendering crashes caused by legacy or incomplete message fields

Fixes #310

Copilot AI review requested due to automatic review settings February 22, 2026 18:34
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 22, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • packages/opencode/src/util/locale.ts - Adds null/undefined safety to titlecase() with a falsy guard clause. Clean and correct defensive change.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a crash in the Kilo CLI when loading sessions with messages by making the Locale.titlecase function safely handle null and undefined values. The issue occurred when attempting to sync sessions between VS Code KiloCode and Kilo CLI, where legacy or incomplete message fields could cause the function to crash with a "str3.replace is not an object" error.

Changes:

  • Modified the titlecase function signature to accept optional and nullable string parameters (string | null | undefined)
  • Added a guard clause to return an empty string for falsy input values, preventing the crash when .replace() is called on null/undefined

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2 to +3
export function titlecase(str?: string | null) {
if (!str) return ""
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new null/undefined handling behavior for the titlecase function is not covered by tests. Consider adding test cases to verify the function correctly returns an empty string when passed undefined, null, or empty string values. This would prevent regression and document the intended behavior.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant