Why is DataTables using alerts?

Why is DataTables using alerts?

EaterOfCorpsesEaterOfCorpses Posts: 4Questions: 0Answers: 0
edited May 2013 in General
My question is why is DataTables using alerts?
this seems to me:
1. bad practice, if you want to tell the developer something, use console.log
2. if you got corrupt data on a public webpage and a user opens it, the user gets an alert thrown in the face because the data is corrupt, while the user got nothing to do with it, and the user will have a bad experience on that site,

yes, I know I can set the error to 'throw' but this means I need to wrap all my calls to dataTables in try{..}catch's

to me when there happens something wrong it should error silently, console.log what's wrong and go further without breaking other stuff.

so why is DataTables using alerts?

Regards, EaterOfCorpses

Replies

  • EaterOfCorpsesEaterOfCorpses Posts: 4Questions: 0Answers: 0
    [code]var alert = function(){ console.log.apply(console,arguments); };[/code]

    seems to solve the issue but is dirty
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Because its amazing how many developers don't know about the console (...) and therefore don't see simple Javascript errors never mind log messages. I know it is not the place of DataTables to try and teach people how to program, but frankly I got fed up answering questions that could be solved by just looking at the console - hence the alert.

    You can use `$.fn.dataTableExt.sErrMode = 'throw'` to have it throw errors rather than using alert().

    Allan
  • EaterOfCorpsesEaterOfCorpses Posts: 4Questions: 0Answers: 0
    edited May 2013
    Thanks for your reply allan :)

    Can I request:
    [code]$.fn.dataTableExt.sErrMode = 'console'[/code]

    this should make developing with dataTables much less frustrating :)

    I made the code for you already ;)

    can you replace

    [code]
    // line 4711: _fnLog
    if ( DataTable.ext.sErrMode == 'alert' )
    {
    alert( sAlert );
    }
    else
    {
    throw new Error(sAlert);
    }
    return;
    [/code]

    with:

    [code]
    switch ( DataTable.ext.sErrMode )
    {
    case 'alert':
    alert( sAlert );
    break;
    case 'console':
    if ( window.console && console.log )
    {
    console.log( sAlert );
    }
    break;
    default:
    throw new Error( sAlert );
    }
    return;
    [/code]

    Regards, EaterOfCorpses
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    I don't see the benefit of `console` over `throw` ? It is throwing an error - not just logging something. Its in an error state when it gets to that point, so I think a throw is correct.

    Allan
  • EaterOfCorpsesEaterOfCorpses Posts: 4Questions: 0Answers: 0
    because when you call throw all the code will stop and it will dig up till the first try{...}catch is found, while when console.log like alert it returns and code continues executing while the throw can make it all stop because you don't have a try{...}catch around it, I don't say that throw, but console.log is sometimes a bit more friendly :)

    Regards, EaterOfCorpses
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Heh - I realise the difference, but I'm saying that when it gets to that point, DataTables is entering into an error state - therefore a throw is more correct, disallowing the code from continuing its execution in an unknown state.

    Allan
This discussion has been closed.