Skip to content

fix: Refactor string truncation logic into reusable utility function to avoid panic (#2818)#2819

Merged
jamadeo merged 5 commits intoblock:mainfrom
toyamagu-2021:fix/2818
Jul 3, 2025
Merged

fix: Refactor string truncation logic into reusable utility function to avoid panic (#2818)#2819
jamadeo merged 5 commits intoblock:mainfrom
toyamagu-2021:fix/2818

Conversation

@toyamagu-2021
Copy link
Copy Markdown
Contributor

@toyamagu-2021 toyamagu-2021 commented Jun 7, 2025

Closes #2818

Motivation

Extract repeated string truncation code from project.rs and session.rs into a new utils module with safe_truncate function.
Also fix trailing
whitespace in configure.rs.

Verification

goose ps works well.

Signed-off-by: toyamagu2021 [email protected]

@toyamagu-2021 toyamagu-2021 changed the title Refactor string truncation logic into reusable utility function fix: Refactor string truncation logic into reusable utility function Jun 7, 2025
@toyamagu-2021 toyamagu-2021 marked this pull request as ready for review June 7, 2025 21:45
Copy link
Copy Markdown
Contributor

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

I'm not a maintainer here, just doing a drive by review since I recently submitted a different PR.

Comment on lines +15 to +20
if s.chars().count() <= max_chars {
s.to_string()
} else {
let truncated: String = s.chars().take(max_chars.saturating_sub(3)).collect();
format!("{}...", truncated)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Totally fine as is, just a note this walks the string twice. Hopefully we aren't passing large file data here anyways.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@toyamagu-2021 toyamagu-2021 changed the title fix: Refactor string truncation logic into reusable utility function fix: Refactor string truncation logic into reusable utility function to avoid panic Jun 8, 2025
@toyamagu-2021 toyamagu-2021 changed the title fix: Refactor string truncation logic into reusable utility function to avoid panic fix: Refactor string truncation logic into reusable utility function to avoid panic (#2818) Jun 8, 2025
Extract repeated string truncation code from project.rs and session.rs
into a new utils module with safe_truncate function. Also fix trailing
whitespace in configure.rs.

Signed-off-by: toyamagu2021 <[email protected]>
@toyamagu-2021 toyamagu-2021 requested a review from jamadeo July 3, 2025 14:36
@toyamagu-2021
Copy link
Copy Markdown
Contributor Author

@jamadeo Sorry, I've fixed lint error.

@toyamagu-2021
Copy link
Copy Markdown
Contributor Author

I've forgotten picking up #3243 🙏

./bin/cargo clippy      
    Checking goose-cli v1.0.31 (/Users/tomoki-yamaguchi/github.com/toyamagu-2021/goose/crates/goose-cli)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.57s

Copy link
Copy Markdown
Collaborator

@jamadeo jamadeo left a comment

Choose a reason for hiding this comment

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

Thanks @toyamagu-2021, looks great.

@jamadeo jamadeo merged commit ff4c7d5 into block:main Jul 3, 2025
9 of 10 checks passed
lifeizhou-ap added a commit that referenced this pull request Jul 4, 2025
* main:
  feat(goose-cli): theme persistence & selection (#1693)
  chore(release): release version 1.0.32 (#3248)
  Add fuzzy file search functionality (#3240)
  update styling of user messages (#3247)
  Add support for escape key to dismiss settings menu (#3225)
  fix: Refactor string truncation logic into reusable utility function to avoid panic (#2818) (#2819)
  fix: Prevent modal from closing on text select. (#3127)
  fix: Add back lazy_static (#3243)
  chore: remove unused dependencies (#3049)
  feat: Add close button (X) to toast notifications (#3197)
  Adds json schema validation to goose recipe validate cli (#3234)
atarantino pushed a commit to atarantino/goose that referenced this pull request Jul 14, 2025
…to avoid panic (block#2818) (block#2819)

Signed-off-by: toyamagu2021 <[email protected]>
Signed-off-by: Adam Tarantino <[email protected]>
s-soroosh pushed a commit to s-soroosh/goose that referenced this pull request Jul 18, 2025
cbruyndoncx pushed a commit to cbruyndoncx/goose that referenced this pull request Jul 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic in goose projects command when handling Japanese text: byte index not on char boundary

3 participants