Forum Discussion

han's avatar
han
Contributor
14 years ago

Bug: Optional parameters in Log.

There seems to be a bug in the Log. functions



The "Optional" Parameters isn't optional!




function WarningExample()

{

  // Specifies a short description of a warning

  var Str = "One instance of the application has already been launched.";

  // Specifies extended text for the warning

  var ExtStr = "One instance of NOTEPAD.EXE has already been launched on the machine.";

  // Specifies a priority for the warning

  var Prior = pmHigher;

  //...

  // Specifies the path to an image

  var sImgPath = "C:\\Work\\MyImj.jpg";

 

  // Posts the warning message to the test log

  Log.Warning(Str, ExtStr, Prior, , sImgPath);

}




6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Try the following.



      Log.Warning(Str, ExtStr, Prior, Log.CreateNewAttributes(),  sImgPath);




    While I understand your assumptions behind leaving that attributes parameter empty, this is invalid code.  That attributes object is expected to be an object type, otherwise it won't work. 



    Optional parameters are optional when they are omitted AND there is not a parameter in use AFTER them that is being filled in.  In your case, you're using the picture parameter which comes after the attributes parameter so you need to at least send in a default attributes object.  This is actually, in my experience, standard for most code languages.
  • han's avatar
    han
    Contributor
    My example was taken from the help pages inside TC :-)

    Is the bug inside the help then?

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Probably.  It does seem to be improper usage within the help docs.  I do get the same problem you do if I leave that field blank.  However, the application, as I understand it, is doing what it should be.
  • karkadil's avatar
    karkadil
    Valued Contributor
    Hi David,



    May we consider this as a feature request then?



    I got stuck with this several years ago as well. I thought that I can skip somehow optional parameters and use only those ones I really need.

    For instance, if I need to post a simple error message with screenshot, instead of writing this



    Log.Error("Error text", "", pmNormal, Log.CreateNewAttributes(), Sys.Desktop.Picture());



    I'd use something like this



    Log.Error("Error text", "errrEx", null, null, Sys.Desktop.Picture());