Menu ▾ ▴

#78 TDefaultMain: exception from the constructor logged twice; --console doc and behaviour after a parameter

closed
nobody
4 days ago
2026-10-16
No

Three points in u_dzDefaultMain:

  1. In Main, an exception from MainClass.Create or from the destructor is logged with LogError('Exception in function Main: ...') and then passed to TDefaultMain.ReportException, which logs it again (LogError('Exception: ...')). Every such exception appears twice in the log. Expected: one entry.

  2. The doc comment of RegisterConsoleOption says that an option --console registered by the program itself "then wins". But Create sets ConsoleOnly from ConsoleSwitchPassed regardless, so a program whose own --console means something else still gets ConsoleOnly = True. Either the doc or the behaviour should change.

  3. HasConsoleSwitch also finds --console after the first plain parameter, e.g. prog input.txt --console, where TGetOpt no longer accepts options: it raises ETooManyParams for it, or, if a parameter takes any number of values, passes --console on as a parameter value while ConsoleOnly is still set. The test TestAmongOtherParams expects exactly this, so it may be intended (a misplaced --console should still keep the error message out of a dialog). If so, it would be worth a sentence in the doc comment of HasConsoleSwitch.

Found by a code review.

Related

Feature Requests: #37

Discussion

  • Thomas Mueller

    Thomas Mueller - 4 days ago

    Fixed in revision [r2490].

     

    Related

    Commit: [r2490]

  • Thomas Mueller

    Thomas Mueller - 22 hours ago

    Note on the change in [r2490] and [r2492]: --console only counts where TGetOpt takes options, i.e. before the first parameter. A misplaced switch such as prog input.txt --console no longer sets ConsoleOnly, so the error TGetOpt reports for it is shown in a dialog, also by a console program. Before, it only went to the console, so an unattended run with such a command line can now block. This is intended and is documented in the doc comments of HasConsoleSwitch and ConsoleOnly.

     

    Related

    Commit: [r2490]
    Commit: [r2492]


Log in to post a comment.