Skip to content

fix(googleai): escape raw newlines in stream response to prevent json decode error#298

Open
Phuocminh94 wants to merge 1 commit into
Robitx:mainfrom
Phuocminh94:patch-1
Open

fix(googleai): escape raw newlines in stream response to prevent json decode error#298
Phuocminh94 wants to merge 1 commit into
Robitx:mainfrom
Phuocminh94:patch-1

Conversation

@Phuocminh94

Copy link
Copy Markdown

Description

When using the Gemini API, the streaming response contains raw, unescaped newlines within the "text" field. This breaks the JSON structure during streaming, causing vim.json.decode to throw a fatal runtime error: Expected object key string but found T_OBJ_END.

Solution

This PR sanitizes the line by escaping raw newlines (\n) and carriage returns (\r) before feeding it into the decoder. Additionally, it wraps the decode process in a pcall to ensure plugin stability even if the stream contains other unexpected formatting anomalies.

Error Log

Lua callback:
.../gp.nvim/lua/gp/dispatcher.lua:323: Expected object key string but found T_OBJ_END at character 25
stack traceback:
	[C]: in function 'decode'
	.../gp.nvim/lua/gp/dispatcher.lua:323: in function 'process_lines'

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.

1 participant