Skip to content

Codeium crashes on vim.fn.json_encode() when triggered in non-UTF-8 buffers (e.g., minified files or preview panels) #322

@agity7

Description

@agity7

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

  1. Open a .min.js, .mjs, or .pem file, or any non-UTF-8 content
  2. Start typing to trigger completions
  3. 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

  1. 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
    
  2. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions