Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

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

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

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
Copy Markdown

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 Kilo-Org/kilocode#6319

@github-actions
Copy link
Copy Markdown
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.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot 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
Copy Markdown
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.
@markijbema markijbema closed this Feb 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants