Server Logs Filled with Invalid Chunk Ignored Errors

Something a little different today. Have you ever look through your server-side logs and seen the following error everywhere:

"Parameters - Parameters: Invalid chunk ignored"

If your requests are improperly formatted, then this error will flood your logs. Although not critical, this can be severally frustrating as it bloats your log files, taking up precious disk space and making them ever more unreadable. As usual with logs, this message is nearly meaningless and doesnt explain how to fix it.

The error is recorded because your requests are malformed. This happens when you are creating a query string and you place an amperes next to the question mark. For example:

http://www.mattsnider.com?&param1=test&param2=abc

Most likely this occurs most frequently when sending AJAX requests as it is easy to sloppily prepend all parameters to the request with an amperes. However, any malformed request can cause this error (not just AJAX requests). To avoid this error all you need to do is ensure that your requests have no amperes next to a ?, and for good measure, ensure that they also dont have any amperes next to each other (such as &&&).

For this purpose I wrote a Function that prepares any AJAX query before passing the query into your AJAX framework (such as YUI connect.js). This method uses two regexes to replace all repeated amperes with a single amperes and also replaces all instances of ?& with just ?. This will allow you to not worry about the format of your queries, however, it is best practice to format your queries without needless amperes.

Example 1: Prepare Query Function

var prepareQuery = function(str) {
	return str.replace(/\\&+/g, &).replace(/\\?\\&/, ?);
};