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.

Error: invalid utf8 byte sequence; invalid continuation byte

See original GitHub issue

Hi,

I am getting the following error whilst trying to parse an event using ethers.js interface.

image

This event emits a string, I assume this has something to do with the problem because before I added the string to the event data emission there was no problem with parsing the log.

The event in solidity:

    event LogExecutionFailure(
        address indexed executor,
        uint256 indexed executionClaimId,
        address payable indexed user,
        IGelatoTrigger trigger,
        IGelatoAction action,
        string executionFailureReason
    );

My ethers script that throws the error:

const abi = [ "event LogExecutionFailure(address indexed executor, uint256 indexed executionClaimId, address indexed user, address trigger, address action, string executionFailureReason)"]

const iface = new ethers.utils.Interface(abi);

const topicExecutionFailure = ethers.utils.id(
      "LogExecutionFailure(address,uint256,address,address,address,string)"
);

const filterExecutionFailure = {
      address: "0x21F7908734A147e084DBEe58C616fd59CE2A0a02",
      fromBlock: parseInt(searchFromBlock),
      topics: [topicExecutionFailure]
};
const logsExecutionFailure = await provider.getLogs(
      filterExecutionFailure
);
for (const log of logsExecutionFailure) {
      const parsedLog = iface.parseLog(log);
....
ERROR throws here
}

Here is a link to the tx that emitted this event on 0x21F7908734A147e084DBEe58C616fd59CE2A0a02 on Kovan

As you can see the correct string (“ErrorTransferFromUser”) is shown as part of the event data on Kovan:

image

Please help me find out why my ethers interface throws when trying to parseLog(log).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
ricmoocommented, Jan 23, 2020

(you might have to skip over 68 bytes instead of 36 to get past a string link too… Maybe try 68 before 36? I’m more confident in that number now that I think about it)

1reaction
gitpushacommented, Jan 26, 2020

(you might have to skip over 68 bytes instead of 36 to get past a string link too… Maybe try 68 before 36? I’m more confident in that number now that I think about it)

Update: This seems to have worked well!

I was able to use the string now in ethers.js

This code does the trick now, as you prescribed.

Do you think this implementation is ok?

I left out this bit:

You would also probably want to add some safety by checking revertReason.length % 32 == 4 and check that the first 4 bytes are the Error(string) selector.

because I catch any evm exceptions during the decoding anyway.

Can you elaborate on this bit revertReason.length % 32 == 4, please? I dont quite get this sanity check. Why == 4?

Thanks again for your great help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UTF-8 Continuation bytes - unicode - Stack Overflow
A continuation byte in UTF-8 is any byte where the top two bits are 10 . They are the subsequent bytes in multi-byte...
Read more >
How to solve UTF8 invalid byte sequence copy errors on a ...
Digging around the internet, I've seen that this is a pretty common problem. The common solution is to use the plain text format...
Read more >
Unicodedecodeerror: 'utf-8' codec can't decode bytes in ...
When working with strings you may have encountered the error "UnicodeDecodeError: 'utf-8' codec can't decode byte X in position X: invalid ...
Read more >
How to Fix Invalid Byte Sequences in UTF-8 - YouTube
What is Unicode?That's what we will talk about in this video!Unicode is a system for character encoding, this allows you to represent an ......
Read more >
A client is getting an error: “Invalid byte sequence for encoding ...
The error messages: "Invalid byte sequence for encoding "UTF8": 0x00" signifies that probably a NULL value was inserted into Database.
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