"URIError" in JavaScript — What It Means and How to Fix It
What the JavaScript error "URIError" means and how to fix it.
Published October 29, 2026
URIError is thrown by decodeURI and decodeURIComponent when given an invalid percent-encoded string.
What it means and why it happens
Typical causes: a stray % character in a URL or invalid UTF-8 sequences.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
URIError: URI malformed
Practical examples
Code that triggers it
decodeURIComponent('%')The fix
try {
decodeURIComponent(input)
} catch {
// fall back to raw input
}Encode properly
encodeURIComponent('100% sure') // '100%25%20sure'Common mistakes
- Decoding unencoded user text.
- Double decoding.
- Not wrapping decode in try/catch for untrusted input.
Key takeaways
- URIError: URIError is thrown by decodeURI and decodeURIComponent when given an invalid percent-encoded string.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Safe decoding helper?
Wrap decodeURIComponent in try/catch and return the original on failure.
How do I find which line caused URIError?
The error message and stack trace show the file and line; start there and work backwards.