[uncaught application error]: TypeError - Invalid CString pointer, not valid UTF-8
See original GitHub issueGetting this error all of a sudden.
I wonder if maybe some non-utf8 strings got into my db? I donj’t know how to fix.
Here’s the query:
.get('/recent', async (context) => {
const links = await context.state.db
.prepare(
'SELECT url, title, excerpt, created_at, count FROM urls ORDER BY created_at DESC LIMIT 50'
)
.all();
context.response.body = links;
})
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:16 (8 by maintainers)
Top Results From Across the Web
'Invalid utf-8 sequence of 1 bytes from index 1' and ' ...
The issue is that CString will try to de-allocate its string when it goes out of scope. Instead you should use CStr which...
Read more >simdjson/basics.md at master
If it is not a valid Unicode (UTF-8) string or if there is an unclosed string, an error may be reported right away....
Read more >Zig Language Reference
In the hello.zig code sample, the main function is declared with the !void return type. This return type is known as an Error...
Read more >Exception Handling — Python 3.11.1 documentation
The first argument specifies the exception type; it is normally one of the standard exceptions, e.g. PyExc_RuntimeError . You need not increment its...
Read more >UTF-8 strings in C (2/3)
What we need is a function that takes a string, checks if the first bytes are a valid UTF-8 encoding and, in case,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

When passing strings to SQLite, we first encode it to a buffer and pass that to bind function. It is possible that since we do not retain any reference to that buffer after calling bind function, it’s getting freed by GC once in a while and when the query is actually run, the data then read from that buffer is corrupted. To overcome that, I have added some measure to retain references to such things so GC cannot free them. @npinochet Would you mind trying the module from https://raw.githubusercontent.com/denodrivers/sqlite3/cstr-fix/mod.ts to see if that fixes the corruption issue? This branch contains that new bind reference code.
Oh if those are unix timestamps - they need to be retrieved as 64 bit integers, while we get 32 bit by default because 64 bit integers make up for BigInts and causes pretty significant performance hit. Try setting
db.int64 = true