Skip to content
Tcl Source Code History Of Ticket 652765
Login

History Of Ticket 652765

Artifacts Associated With Ticket 652765

  1. Ticket change [0922c7ccf0] (rid 89665) by nobody on 2002-12-12 16:49:39:

    1. assignee initialized to: "dkf"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Errors occuring in "trace add command" callbacks (i.e.,
      rename and delete callbacks) are swallowed by Tcl
      instead of being propagated to the application.
      
      [email protected]
      
    4. foundin initialized to: "obsolete: 8.4.1"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "18. Commands M-Z"
    10. title initialized to: "errors disappear in trace callbacks"
    11. type initialized to: "Bug"
  2. Ticket change [eef06c9ff9] (rid 108908) by dkf on 2002-12-20 16:45:12:

    1. assignee changed to: "vincentdarley"
  3. Ticket change [35885e5cc0] (rid 106952) by vincentdarley on 2003-01-17 18:32:17:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      This is true, and the code quite explicitly ignores all
      errors. This is not documented however.  I quite open about
      what the correct behaviour should be (as long as we then
      document it), but there is one major problem with not
      swallowing errors: rename and delete operations are defined
      to succeed always, irrespective of any errors thrown. So,
      what do we do if there are two traces, each of which throw
      an error? We discard the first error message?  What if the
      first trace throws an error and the second is ok?  Do we
      still discard the error?  In some ways the current behaviour
      is the most consistent.
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  4. Ticket change [f76a9355b6] (rid 91376) by hemanglavana on 2003-01-17 20:18:29:

    1. icomment:
      Logged In: YES 
      user_id=81875
      
      I think it should bail out at the first occurence of an
      error in a callback proc. Not doing so will make it very
      difficult to find/debug such errors. Moreover, execution
      traces bail out as soon as an error is encountered and the
      behavior should be the same for rename/delete traces as well.
      
      Do we need a tip to make this change? I already have a patch
      to fix this ... I just need to add few test cases to
      trace.test and update the docs also.
      
      
    2. login: "hemanglavana"
    3. mimetype: "text/plain"
    4. username: "hemanglavana"
  5. Ticket change [406f3fec42] (rid 121626) by dkf on 2003-06-26 17:28:39:

    1. subsystem changed to: "46. Traces"
  6. Ticket change [178d59b759] (rid 122514) by vincentdarley on 2003-06-26 20:43:43:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      Here are the basic options:
      
      (i) If rename/delete always delete the command/proc in 
      question. This implies either all errors in traces must be 
      ignored, or an error in a trace stops the execution of any 
      other trace, but lets the delete still happen afterwards 
      anyway. In any case, if the command in question has 
      a 'Tcl_CmdDeleteProc' which itself wants to create an error 
      message, that error would overwrite any error thrown by a 
      trace.
      
      (ii) If rename/delete are (like variable 'unset' traces) allowed 
      to fail with an error, then things are conceptually much 
      cleaner: the first trace which throws an error aborts the 
      operation. However, this is an overall change in Tcl's 
      documented behaviour, and would require quite careful coding 
      to get right.
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  7. Ticket change [c065497d92] (rid 102394) by dgp on 2003-06-26 22:46:54:

    1. assignee changed to: "dgp"
  8. Ticket change [2f04e47c07] (rid 92982) by duquette on 2004-08-22 01:14:19:

    1. icomment:
      Logged In: YES 
      user_id=372859
      
      Here's an example of where the current code causes a problem: in object 
      code (e.g., Tcllib's struct::stack) the object name is often used as an 
      index into array in which the specific object's data is stored.  If the object 
      is renamed, this breaks.  An obvious use of a rename trace is to throw 
      an error if the object is renamed.  At present, you can't do that and 
      make it stick without installing a modified version of the "rename" 
      command.
      
      Look at it another way--if errors in rename and delete callbacks  
      propagated normally, the programmer could achieve the current behavior 
      using "catch".  With the code as it is, the programmer has no choice.
      
      This is not academic, either; Snit relies on the rename/destroy callbacks.
      
      
    2. login: "duquette"
    3. mimetype: "text/plain"
    4. username: "duquette"
  9. Ticket change [cc217b55b5] (rid 95641) by dkf on 2004-08-23 17:42:26:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      One possibility I've used elsewhere would be to report
      traces using the background error message mechanism. As long
      as people have a [bgerror] command defined (and are running
      the event loop), the error message will go somewhere where
      it can be picked up...
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  10. Ticket change [38d80a30b2] (rid 112282) by vincentdarley on 2004-08-23 20:10:08:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      In Will's example, I would've said a more obvious use of
      rename traces in struct::stack would be to rename the array
      entries so that the code still works after rename.
      
      I still don't quite understand _exactly_ what Will (or
      anyone) means by 'if ... propagates normally'?
      
      What happens if one rename trace succeeds but then the next
      one throws an error?  In Will's example, let's say there
      were two traces. Now, if the first trace succeeds (causing
      some side effect of renaming appropriate associated
      information), but a second trace fails, then the original
      rename will not take place and the first trace will actually
      have done the wrong thing. 
      
      Can someone please define a consistent behaviour, if they
      have one in mind that is different to what we have now?
      
      
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  11. Ticket change [81ff05818c] (rid 117144) by dgp on 2004-08-24 00:14:58:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      Is the real problem here one of using
      a tranisient, user-modifiable thing -- the
      command's name -- rather than a more
      permanent token of some kind as the
      index against which to store data?
      
      Simliar to having a Tcl_ObjCmdProc
      that changes behavior based on
      the value of objv[0] rather than storing
      and behavior controlling value in
      the ClientData ?
      
      Not that I wouldn't like a sensible solution
      to this problem, but the motivating example
      here might be a subtle instance of
      pilot error.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  12. Ticket change [6b23c3832d] (rid 128268) by duquette on 2004-08-24 07:24:07:

    1. icomment:
      Logged In: YES 
      user_id=372859
      
      By "propagate normally", I mean that if 
      
         rename SomeName SomeOtherName
      
      causes a trace to throw an error, then the error propagates up and is
      returned by "rename".  I think the concern about multiple traces is
      misleading.  After all, why would a rename callback throw an error? 
      I can think of two reasons: 
      
      1. The callback threw an error explicitly, becausing renaming the 
          command will cause the program to misbehave in mysterious
          ways.
      
      2. There's an error in the callback, meaning it didn't do what it was
          supposed to do, meaning that the program is likely to misbehave
          in mysterious ways.
      
      In either case, there's probably no good way to recover from the
      error; it needs to be fixed.  Better that the programmer find out
      ASAP, while they are developing the software.  But as it is, 
      such errors hide and can be monstrously difficult to debug.
      
      Regarding using a more permanent token rather than the command
      name--well, yes, obviously.  If you can.
      
      
      
      
    2. login: "duquette"
    3. mimetype: "text/plain"
    4. username: "duquette"
  13. Ticket change [8a681adf77] (rid 127389) by vincentdarley on 2004-08-25 16:29:24:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      Will,
      
      If your purpose is just to discover programming errors, then
      that's one thing (which could also be handled by dgp's
      suggestion of calling bgerror with the problem -- in fact
      calling bgerror might be better, because the programmer
      would not be tempted to use 'catch' to hide the problem).
      
      However, earlier you gave an example of using a trace in
      tcllib to prevent renaming of an structure. That's certainly
      not just to discover programming errors. It's to use the
      error to signal a certain condition, which a programmer
      might wish to catch and workaround.
      
      So which of these two is it?
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  14. Ticket change [0d32ed30c7] (rid 114318) by duquette on 2004-08-25 21:15:05:

    1. icomment:
      Logged In: YES 
      user_id=372859
      
      Vince,
      
      Using bgerror really only works well if you're running an app with an 
      event loop.  There are lots of Tcl applications that don't, and Snit (my 
      particular interest) can be used in both.  So I can't just use bgerror to 
      flag errors in Snit's rename trace callback.
      
      You ask "which of these two is it?"  Am I trying to discover programming 
      errors, or am I trying to signal conditions that a programmer might wish 
      to catch?
      
      The answer is, "both".  I like Tcl's error handling; I really dislike having 
      code in which errors can occur silently.  For that reason, I'm 
      philosophically against the current implementation, as it's the one place 
      (that I'm aware of) in which errors are ignored without recourse.  
      (Bgerror is not a real recourse, for the reason I stated above.)
      
      But in any event, it's a false dichotomy.  If I have a module which--for 
      whatever reason--contains commands that should not be renamed, it 
      seems reasonable to use a rename trace to catch attempts to rename 
      them, and throw an error if they do, just as some folks use variable 
      traces to control what can be assigned to particular variables.  If errors 
      are thrown in these cases, it's probably not a "condition which a 
      programmer might wish to catch and workaround"; it's a logical error in 
      the program that has to be fixed.
      
      Will
      
      
    2. login: "duquette"
    3. mimetype: "text/plain"
    4. username: "duquette"
  15. Ticket change [e74f35cde6] (rid 104435) by dgp on 2004-08-25 21:20:14:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      I think I have to disagree on part of that.
      
      It's a property of Tcl commands that they
      can be renamed.  A package that wants
      to prevent the renaming of its commands
      seems buggy to me.
      
      Generally, though, I agree that it's best
      to avoid swallowing and silently hiding errors
      when we can.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  16. Ticket change [73bab44930] (rid 105088) by dkf on 2004-08-25 21:27:59:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      There are a few other places where errors are silently
      gobbled and IMO they're all bugs.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  17. Ticket change [057aa66c91] (rid 89071) by vincentdarley on 2004-08-25 21:35:21:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      I agree it is undesirable to swallow errors, but the
      suggested approach can still lead to inconsistencies. 
      Looking closely, the current variable tracing approach also
      has a similar problem, for example:
      
      set foo 3
      trace add variable foo write {puts "1: foo is $foo" ; #}
      trace add variable foo write {set foo 3 ; error "don't
      change" ; #}
      trace add variable foo write {puts "2: foo is $foo" ; #}
      
      If I now try to 'set foo 2', the last trace fires and thinks
      that foo is 2, but then the next trace actually sets foo to
      3 and throws an error, aborting the change.
      
      The upshot is that one of the traces was confused, and
      believed the variable was set to 2 when it wasn't.
      
      A similar, but more fundamental problem will occur with
      rename traces, if we allow them to be aborted by an error. 
      One trace can think something has been renamed, but then the
      next trace aborts the rename.  Now we are in an inconsistent
      state.
      
      So, as I've said, I'm all for not swallowing errors, but I'm
      not very keen on inconsistent states either.
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  18. Ticket change [84874d9b77] (rid 117566) by duquette on 2004-08-26 06:48:33:

    1. icomment:
      Logged In: YES 
      user_id=372859
      
      Vince said: "So, as I've said, I'm all for not swallowing errors, but I'm
      not very keen on inconsistent states either."
      
      Precisely.  If a bug in a rename trace callback causes an error to be 
      thrown, and it gets swallowed, then very likely your program is now in 
      an inconsistent state.
      
      That is, it's in an inconsistent state whether the error is swallowed or 
      not--but if the error isn't swallowed, the developer is more likely to catch 
      it and fix it before the software is released.
      
      
      
    2. login: "duquette"
    3. mimetype: "text/plain"
    4. username: "duquette"
  19. Ticket change [13a17d899c] (rid 124257) by vincentdarley on 2004-08-26 15:26:38:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      Sorry, I disagree.  If errors are swallowed then we have a
      well-defined, consistent behaviour: command renames and
      deletes always succeed.  Therefore all trace callbacks can
      assume that is true.
      
      Of course this doesn't mean that a badly written callback
      can't accidentally throw an error and therefore not succeed
      and therefore leave _itself_ in an inconsistent state. But
      that is an example of the programmer causing themselves a
      problem.
      
      However, if errors propagate, then the example I gave shows
      how one trace callback can abort a 'rename' and therefore
      cause problems to another trace callback which doesn't know
      the rename was aborted.
      
      This means that one programmer can shoot another programmer
      in the foot.  That's the inconsistency I don't like. There's
      a distinction between 'your program being in an inconsistent
      state' and 'this piece of code is in an inconsistent state
      not because it contains any bugs but because a totally
      different piece of code contains bugs'.
      
      It's also why I like the 'bgerror' solution because it
      avoids this inconsistency. (But your points about the event
      loop are good, and mean we effectively have to rule that
      solution out).
      
      Now, it may well be that allowing this inconsistency is the
      best way forward, trading it off for better debugging (i.e.
      receiving an error message), but it would be nice if we can
      find a more consistent approach.
      
      
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  20. Ticket change [7f876df2f1] (rid 97575) by dkf on 2004-08-26 16:02:32:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      Summing up:
       1) Do we propagate errors?
       2) If we propagate errors, do we do this directly or via
      some kind of background mechanism?
       3) If we propagate errors directly, do we permit them to
      abort the renaming or prevent other rename traces from
      getting called?
      
      IMO:
        1) Yes
        2) bgerror is good, but other can work
        3) the error should *not* abort the rename
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  21. Ticket change [1ebd016e05] (rid 91028) by vincentdarley on 2004-08-26 17:07:08:

    1. icomment:
      Logged In: YES 
      user_id=32170
      
      Totally agree with dkf's summary.  Only remaining question
      is how do we carry out (2)?  (Note: this is a very similar
      problem to that faced by the tclvfs extension, which uses
      'vfs::filesystem internalerror $cmdprefix' to specify a
      command prefix to call whenever there's an error).
      
      One possibility would be to use the 'tclLog' proc which
      appears to be built into Tcl.  I'm not really sure what
      'tclLog' is documented to do, but it does exist!  (In fact
      it might be a good idea of tclvfs to use it instead of its
      own ad-hoc approach).
      
      
      
      
      
    2. login: "vincentdarley"
    3. mimetype: "text/plain"
    4. username: "vincentdarley"
  22. Ticket change [070897947b] (rid 89316) by dkf on 2004-08-26 17:26:01:

    1. icomment:
      Logged In: YES 
      user_id=79902
      
      Note that delete traces have the same properties; both kinds
      are notifications to be done after the fact.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  23. Ticket change [6dbd09c6ac] (rid 128752) by duquette on 2004-08-27 06:02:04:

    1. icomment:
      Logged In: YES 
      user_id=372859
      
      I think Donal's suggestion, that the errors are propagated but that the 
      rename succeeds, makes a lot of sense.
      
      IF some background mechanism is used, though, it will need to be clearly 
      documented in the trace.n man page.
      
      
    2. login: "duquette"
    3. mimetype: "text/plain"
    4. username: "duquette"
  24. Ticket change [6133f6bb87] (rid 92205) by dgp on 2005-07-05 22:55:14:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      A re-reading of the comments suggest
      that a (near-) agreement was reached
      on what ought to be done.  Did it ever
      get done?
      
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  25. Ticket change [ffe3bb9ad3] (rid 108841) by dgp on 2005-07-08 04:03:40:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      [16:59]dgpI see agreement that command traces ought to
      report errors and ought not to abandon the rename/delete
      task they are performing...
      [17:00]dkf_ISTR that too
      [17:00]dgp...do you agree that the first error ought to be
      reported, and subsequent traces don't get done?
      [17:00]dkf_I could live with that
      [17:01]dkf_(errors shouldn't happen at all )
      [17:01]dgpok, I'll try that patch first, and we can argue
      whether it needs changing when reviewing the patch. 
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  26. Ticket change [50745febb2] (rid 125970) by dgp on 2005-08-02 02:55:23:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      It appears that in order to make
      this conversion completely, we'll
      need to revise the spec for
      Tcl_DeleteCommandFromToken()
      to allow it to return non-TCL_OK
      return codes.  So I think we're looking
      at a TIP.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  27. Ticket change [c59586c4b0] (rid 112023) by dgp on 2005-08-02 03:11:57:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      hmmm... but that then raises
      questions about the callers
      of Tcl_DeleteCommandFromToken()
      and how they ought to react to
      an error from a command deletion
      callback.  Consider [namespace delete],
      [namespace forget], [interp delete],
      [interp alias $i $c {}], and Tk's [destroy].
      
      Consider also, the implicit command delete
      that happens when a new command
      creation overwrite a previous one.
      
      Beginning to see why this didn't get
      done "right" in the first place. :^(
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  28. Ticket change [25074dbda3] (rid 131211) by dgp on 2013-01-08 01:57:51:

    1. priority changed to: "9 Immediate"
  29. Ticket change [02eb0798f4] (rid 119735) by dkf on 2013-01-08 16:00:36:

    1. icomment:
      Note that it's also not *quite* as critical as it was for TclOO, as the [$obj destroy] method runs destructors at a point when it is possible to correctly propagate errors. Still, there's no guarantee that an object will be deleted so nicely.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  30. Ticket change [11efa855dd] (rid 95228) by dgp on 2013-04-10 23:28:21:

    1. priority changed to: "5 Medium"