[v2.0.2] Unexpected control creation after error Topic is solved

Report problems with documented functionality
User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

[v2.0.2] Unexpected control creation after error

Post by RaptorX » 06 Jun 2023, 11:50

hi guys,

When adding control with an existing name AHK throws and error but unexpectedly creates the control anyways.

Code: Select all

main := gui()

main.addedit('vMyTest w150', 'test')
main.addedit('vMyTest w150', 'testing')
main.show()

msgbox main['MyTest'].text
I think it is unexpected because the msgbox then becomes an ambiguous line as we dont know which of the two controls we are referring to (it defaults to the first created though).

I think that if AHK is going to create the control anyways that message should be a warning instead.
Projects:
AHK-ToolKit

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2.0.2] Unexpected control creation after error  Topic is solved

Post by lexikos » 20 Jun 2023, 03:51

v2.0.3 fixes a bug where choosing "Abort" after this error is displayed does not abort the thread.

I was going to say that I don't agree with your logic about error vs. warning, but then realized you haven't actually given any reasoning.

If anything, "the behaviour of the script becomes ambiguous" is a good reason to not continue execution of the script.

I suppose these are the possible outcomes:
  • Only the first control is created.
  • Both controls are created, with the second one having no name.
  • Both controls are created with the same name, but only one can be accessed with main['MyTest'].
And these are the possible expectations:
  • Only one control is created. Why are there two calls to addedit()? If the options differ, which ones were supposed to apply?
  • Both controls are created, and main['MyTest'] will refer to whichever control the author intended at the time. Of course, it is impossible if the author intends to refer to two different controls. Even if they intend to refer to only one of the controls, it is not reasonable because there is no guarantee about which control they'll get.
  • Both controls are created, and main['MyTest'] will not be used. Duplicate names wouldn't necessarily prevent the script from using Ctrl.Name in a logical way.
If the thread is aborted during construction of the GUI, the GUI still exists (unless automatic reference counting has caused it to be destroyed), but is very unlikely to be in the correct state. In that case, it doesn't matter whether the control was created or whether it has a name. There are exceptions, such as if a control is added from a different thread than the one which created the GUI, but they are edge cases.

Finally, if an option is detected as invalid, an error is raised. If the user chooses to continue (or if an OnError callback has that effect), the invalid option is ignored and the control is created. If the user does not choose to continue, or if the method call is wrapped in try and therefore doesn't give the user this choice, the control is not created.

guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: [v2.0.2] Unexpected control creation after error

Post by guest3456 » 21 Jun 2023, 06:29

lexikos wrote:
20 Jun 2023, 03:51
v2.0.3
looks like you missed an annoucement post for this


User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: [v2.0.2] Unexpected control creation after error

Post by RaptorX » 21 Jun 2023, 12:14

guest3456 wrote:
21 Jun 2023, 06:29
lexikos wrote:
20 Jun 2023, 03:51
v2.0.3
looks like you missed an annoucement post for this
I did not, I posted this bug before 2.0.3 was available :P
Projects:
AHK-ToolKit

guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: [v2.0.2] Unexpected control creation after error

Post by guest3456 » 21 Jun 2023, 12:44

RaptorX wrote:
21 Jun 2023, 12:14
I did not, I posted this bug before 2.0.3 was available :P
i was talking about lexikos, he didnt put out an announcement about the new release with the changelog


User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: [v2.0.2] Unexpected control creation after error

Post by RaptorX » 21 Jun 2023, 12:48

guest3456 wrote:
21 Jun 2023, 12:44
RaptorX wrote:
21 Jun 2023, 12:14
I did not, I posted this bug before 2.0.3 was available :P
i was talking about lexikos, he didnt put out an announcement about the new release with the changelog
Oh yeah you are right, i noticed the update because im suscribed to the github repository, but i didnt see an announcement post in the forums. :lol:
Projects:
AHK-ToolKit

User avatar
RaptorX
Posts: 371
Joined: 06 Dec 2014, 14:27
Contact:

Re: [v2.0.2] Unexpected control creation after error

Post by RaptorX » 21 Jun 2023, 13:12

I was going to say that I don't agree with your logic about error vs. warning, but then realized you haven't actually given any reasoning.
Yeah I was just following what I have noticed to be a perceived pattern in the AutoHotkey Error handler that when you get a warning you get the "continue" button which is what I would expect: a warning is just telling you that things might not behave as you expect but you can continue execution. In the case of an Error the script is stopped and you have to fix the error before running the script again.

Following that perceived pattern I found it unexpected to get an Error but then having the script continue.
Projects:
AHK-ToolKit

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2.0.2] Unexpected control creation after error

Post by lexikos » 21 Jun 2023, 17:10

Most errors also give a "Continue" button in v2, which I alluded to in my previous post. You should not find it unexpected for the script to continue after clicking "Continue", error or not. You should find it unexpected for the script to continue after clicking "Abort".

You didn't initially mention the script continuing, only the control being created. Evidently the latter can happen even if the former does not.

Post Reply

Return to “Bug Reports”