Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix json decode error when jsonContent is emtpy #151

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

oblank
Copy link

@oblank oblank commented Jan 28, 2024

What

ignore empty string when json decode, it may case some issure, such as #128

Why

fix bug

Affected Areas

json decode when openai response

Copy link

sonarcloud bot commented Jan 28, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@ActuallyTaylor
Copy link

ActuallyTaylor commented Jan 28, 2024

I also found and fixedthis issue, however I think a much better fix is to just change:

let jsonObjects = "\(previousChunkBuffer)\(stringContent)"
    .components(separatedBy: "data:")
    .filter { $0.isEmpty == false }
    .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }

to:

let jsonObjects = "\(previousChunkBuffer)\(stringContent)"
    .components(separatedBy: "data:")
    .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
    .filter { $0.isEmpty == false }

Simply moving the filter down by one line fixes this and does not require any other changes or checks.

My fork shows the fix if anyone is curious about the difference.

@ingvarus-bc
Copy link
Contributor

Thanks for your contribution! 🔥

@ingvarus-bc ingvarus-bc merged commit 38cda2a into MacPaw:main Feb 2, 2024
4 checks passed
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.

None yet

3 participants