question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[uncaught application error]: TypeError - Invalid CString pointer, not valid UTF-8

See original GitHub issue

Getting 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
DjDeveloperrcommented, Sep 29, 2022

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.

1reaction
DjDeveloperrcommented, Sep 19, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found