JavaScript Error
URIError
URIError is thrown when a global URI handling function (encodeURI, decodeURI, encodeURIComponent, decodeURIComponent) is given a malformed URI or the string to decode contains invalid percent-encoding sequences.
Common causes
- Decoding a string with invalid percent-encoding (e.g., %ZZ)
- Encoding a string with unpaired surrogates
- Passing malformed URI strings to decodeURIComponent()
- Double-encoding or double-decoding URIs
- Handling user-provided URLs without validation
How to fix it
- Wrap decodeURIComponent() calls in try/catch
- Validate URI strings before decoding
- Use the URL constructor for parsing URLs safely
- Avoid double-encoding by checking if already encoded
- Sanitize user input before URI operations
Example
URIError example
// Error example
decodeURIComponent("%ZZ");
// URIError: URI malformed
decodeURI("%E0%A4%A");
// URIError: URI malformed
// Fix with try/catch
function safeDecode(str) {
try {
return decodeURIComponent(str);
} catch (e) {
return str; // Return original if invalid
}
}
// Fix with URL constructor
const url = new URL("https://example.com/path?q=hello%20world");
console.log(url.searchParams.get("q")); // "hello world" Track URIError with Checkend
Checkend automatically captures URIError errors in your JavaScript application with full context:
- Complete stack trace with source maps
- Browser and environment context
- Automatic grouping of similar errors
- Instant notifications when errors occur
Related errors
TypeError
TypeError is raised when an object is not of the expected type. This happens when Ruby can't implici...
SyntaxErrorSyntaxError is raised when Ruby's parser encounters code that doesn't conform to Ruby's syntax rules...
RangeErrorRangeError is thrown when a value is not in the expected range. This includes invalid array lengths,...
Stop debugging in production
Get full error context and fix issues faster with self-hosted error tracking.