1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-30 23:52:11 +01:00

Update: Provide link to technical note explaining errors for DT logged

errors

- A lot of posts in the forum are questions such as "what does the
  invalid JSON response" error mean, or "how to fix the unknown
  requested parameter error". To address these, rather than having them
  answered individually in the forum, I'm going to write a series of
  technical notes for DataTables (getting started, how to use columns
  etc) and as part of those, each error that DataTables can fire off
  will have a technical note explaining in deatil what the error means.

- Example:
   DataTables warning: table id=example - Invalid JSON response. For
   more information about this error, please see
   http://datatables.net/tn/1

- This commit puts the required logic in place. The technical notes
  don't exist yet, but they will soon. They will be:

1 - Invalid JSON response
2 - Non-table node initialisation ({this.nodeName})
3 - Cannot reinitialise DataTable
4 - Requested unknown parameter {param} for row {idx}
5 - Unknown paging action: {action}
6 - Possible column misalignment
		- The table cannot fit into the current element which
		  will cause column

- This also has the advantage that the errors in the DataTables code can
  be a little smaller. Around 500 bytes saved.

- This fixes issue #173
This commit is contained in:
Allan Jardine 2013-05-26 09:15:21 +01:00
parent 1b8f4608ac
commit 7f1dfc2b38
6 changed files with 39 additions and 52 deletions

View File

@ -59,7 +59,7 @@ function _fnBuildAjax( oSettings, data, fn )
"type": oSettings.sServerMethod, "type": oSettings.sServerMethod,
"error": function (xhr, error, thrown) { "error": function (xhr, error, thrown) {
if ( error == "parsererror" ) { if ( error == "parsererror" ) {
oSettings.oApi._fnLog( oSettings, 0, "DataTables: invalid JSON response" ); oSettings.oApi._fnLog( oSettings, 0, 'Invalid JSON response', 1 );
} }
} }
}; };

View File

@ -9,8 +9,7 @@ var oInitEmpty = oInit === undefined ? true : false;
/* Sanity check */ /* Sanity check */
if ( this.nodeName.toLowerCase() != 'table' ) if ( this.nodeName.toLowerCase() != 'table' )
{ {
_fnLog( null, 0, "Attempted to initialise DataTables on a node which is not a "+ _fnLog( null, 0, 'Non-table node initialisation ('+this.nodeName+')', 2 );
"table: "+this.nodeName );
return; return;
} }
@ -45,9 +44,7 @@ for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
} }
else else
{ {
_fnLog( DataTable.settings[i], 0, "Cannot reinitialise DataTable.\n\n"+ _fnLog( DataTable.settings[i], 0, 'Cannot reinitialise DataTable', 3 );
"To retrieve the DataTables object for this table, pass no arguments or see "+
"the docs for bRetrieve and bDestroy" );
return; return;
} }
} }

View File

@ -159,8 +159,8 @@ function _fnGetCellData( oSettings, iRow, iCol, sSpecific )
if ( oSettings.iDrawError != oSettings.iDraw && oCol.sDefaultContent === null ) if ( oSettings.iDrawError != oSettings.iDraw && oCol.sDefaultContent === null )
{ {
_fnLog( oSettings, 0, "Requested unknown parameter "+ _fnLog( oSettings, 0, "Requested unknown parameter "+
(typeof oCol.mData=='function' ? '{mData function}' : "'"+oCol.mData+"'")+ (typeof oCol.mData=='function' ? '{function}' : "'"+oCol.mData+"'")+
" from the data source for row "+iRow ); " for row "+iRow, 4 );
oSettings.iDrawError = oSettings.iDraw; oSettings.iDrawError = oSettings.iDraw;
} }
return oCol.sDefaultContent; return oCol.sDefaultContent;

View File

@ -99,7 +99,7 @@ function _fnPageChange ( settings, action )
} }
else else
{ {
_fnLog( settings, 0, "Unknown paging action: "+action ); _fnLog( settings, 0, "Unknown paging action: "+action, 5 );
} }
var changed = settings._iDisplayStart !== start; var changed = settings._iDisplayStart !== start;

View File

@ -392,16 +392,9 @@ function _fnScrollDraw ( o )
} }
/* And give the user a warning that we've stopped the table getting too small */ /* And give the user a warning that we've stopped the table getting too small */
if ( o.oScroll.sX === "" ) if ( o.oScroll.sX === "" || o.oScroll.sXInner !== "" )
{ {
_fnLog( o, 1, "The table cannot fit into the current element which will cause column"+ _fnLog( o, 1, 'Possible column misalignment', 6 );
" misalignment. The table has been drawn at its minimum possible width." );
}
else if ( o.oScroll.sXInner !== "" )
{
_fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
" misalignment. Increase the sScrollXInner value or remove it to allow automatic"+
" calculation" );
} }
} }
else else

View File

@ -1,52 +1,49 @@
/** /**
* Return the settings object for a particular table * Return the settings object for a particular table
* @param {node} nTable table we are using as a dataTable * @param {node} table table we are using as a dataTable
* @returns {object} Settings object - or null if not found * @returns {object} Settings object - or null if not found
* @memberof DataTable#oApi * @memberof DataTable#oApi
*/ */
function _fnSettingsFromNode ( nTable ) function _fnSettingsFromNode ( table )
{ {
for ( var i=0 ; i<DataTable.settings.length ; i++ ) var settings = DataTable.settings;
{ var idx = $.inArray( table, _pluck( settings, 'nTable' ) );
if ( DataTable.settings[i].nTable === nTable )
{
return DataTable.settings[i];
}
}
return null; return idx !== -1 ?
settings[ idx ] :
null;
} }
/** /**
* Log an error message * Log an error message
* @param {object} oSettings dataTables settings object * @param {object} settings dataTables settings object
* @param {int} iLevel log error messages, or display them to the user * @param {int} level log error messages, or display them to the user
* @param {string} sMesg error message * @param {string} msg error message
* @param {int} tn Technical note id to get more information about the error.
* @memberof DataTable#oApi * @memberof DataTable#oApi
*/ */
function _fnLog( oSettings, iLevel, sMesg ) function _fnLog( settings, level, msg, tn )
{ {
var sAlert = (oSettings===null) ? msg = 'DataTables warning: '+
"DataTables warning: "+sMesg : (settings!==null ? 'table id='+settings.sTableId+' - ' : '')+msg;
"DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg;
if ( iLevel === 0 ) if ( tn ) {
{ msg += '. For more information about this error, please see '+
if ( DataTable.ext.sErrMode == 'alert' ) 'http://datatables.net/tn/'+tn;
{
alert( sAlert );
} }
else
{ if ( ! level ) {
throw new Error(sAlert); if ( DataTable.ext.sErrMode == 'alert' ) {
alert( msg );
} }
return; else {
throw new Error(msg);
} }
else if ( window.console && console.log ) }
{ else if ( window.console && console.log ) {
console.log( sAlert ); console.log( msg );
} }
} }