Summary
Codeium sometimes crashes with Vim:E474: String ... contains byte that does not start any UTF-8 character when trying to generate completions on buffers containing non-UTF-8 or binary-like content.
How to Reproduce
- Open a
.min.js, .mjs, or .pem file, or any non-UTF-8 content
- Start typing to trigger completions
- Neovim crashes with this error:
[C]: in function 'json_encode'
.../codeium.nvim/lua/codeium/io.lua:410: in function 'post'
...
Cause
vim.fn.json_encode() is being called on raw buffer content without verifying if the buffer:
- Is valid UTF-8
- Is of a proper filetype (
nofile, prompt, etc.)
- Should be excluded (Telescope, Spectre, etc.)
Suggested Fix
- Wrap
vim.fn.json_encode(payload) in pcall() to avoid crashing:
local ok, encoded = pcall(vim.fn.json_encode, payload)
if not ok then return end
- Don’t trigger completions in buffers with:
buftype ~= ""
filetype == "TelescopePrompt"
buffer filename under .codeium/
Why This Matters
This bug silently crashes Codeium in common dev workflows. Users editing modern JS/TS stacks or using preview UIs (Telescope, Spectre) hit this often.
Thanks!