URIError: URI malformed — why does decodeURIComponent fail?

decodeURIComponent() failed while interpreting a URL component. Look at the raw value before any parsing step changes it. A lone percent sign, a percent escape with missing digits, or an invalid UTF-8 sequence can all interrupt decoding. An earlier decode can also leave literal characters that were never meant to be decoded again.
Confirm where the component was encoded and which layer is responsible for decoding it. Every percent escape needs two hex digits, and the escaped bytes must form valid text. If the value came from outside the application, handle malformed input at that boundary.
Use the incomplete escape in the snippet to exercise the same error branch as malformed external input. Compare a known-good encoded value with the failing one and check whether another layer already decoded it. Fixing the producer or removing a duplicate decode keeps the handling predictable across valid and invalid inputs.
const raw = '%E0%A4%A'; // Incomplete UTF-8 percent sequence try { console.log(decodeURIComponent(raw)); } catch (error) { if (error instanceof URIError) console.warn('Bad encoded value'); }
Capture the raw component before decoding and compare it with the correctly encoded value from its source.