[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function declarations produce no trace nor trigger debug trap while

From: Erik Adelbert
Subject: Re: Function declarations produce no trace nor trigger debug trap while having side effects
Date: Fri, 28 Oct 2022 18:09:35 +0200

Hello Chet and other bash maintainers,

Thanks for your time.

> On 27 Oct 2022, at 23:26, Chet Ramey <chet.ramey@case.edu> wrote:
> we believe the current semantic to be at least unclear and would like to see 
> either:
>> 0 the DEBUG trap called _before_ any function declaration (preferred)
> While calling the DEBUG trap before certain compound commands has value, I
> don't think that function definition commands rise to that level.

In the demonstrated case (2nd example of our report), we made clear that
commenting in/out a function definition *seemed* to make an unrelated
error appear/disappear from the debugging support because it was in the

The explanation lies in the trap *and* function parts of bash documentation:
    1 there is an error
    2 the debug TRAP is not invoked before the function definition
    3 the function definition is required to return 0 if successful
    4 the debug TRAP is invoked after the successful function definition

This results in an effective masking of the error from the debugging
support. Function definitions are hardly thought to do that and this situation 
could be the starting point of a slow failure with a super-cloaked origin.

Making a call to the DEBUG trap has some value here:
    * it does not compromise existing workflows
    * it would make the error visible and actionable by a debugging logic 
    * the workflow would always-ish be the same as if the next command 
      was not, well, a function definition
Finally, we are using the DEBUG trap and a bunch of pure-bash routines to
devise a lightweight and efficient error handling scheme for bash scripts. We
believe it to be of interest and have plan to release it. This handler helped 
found the reported problem and would benefit from the proposed modification.

Thanks again and regards,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]