helpThe GNU Bourne-Again SHell - Support: sr #108750, $LINENO and $BASH_SOURCE are...

 
 

sr #108750: $LINENO and $BASH_SOURCE are inconsistent in ERR trap on function return

Submitted by:  Paul Donohue <paulsd>
Submitted on:  Thu 19 Feb 2015 07:32:29 PM UTC  
 
Category: NonePriority: 5 - Normal
Severity: 3 - NormalStatus: Done
Privacy: PublicAssigned to: None
Open/Closed: OpenOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Tue 23 Jun 2015 09:05:02 PM UTC, comment #1:

This has been fixed:
http://lists.gnu.org/archive/html/bug-bash/2015-02/msg00132.html

I would close this bug, but it doesn't look like I am allowed to do so.

Paul Donohue <paulsd>
Thu 19 Feb 2015 07:32:29 PM UTC, original submission:

When an ERR trap is called, ${BASH_SOURCE[0]}, ${FUNCNAME[0]}, and $LINENO normally indicate the file/function/line which called the command that returned a non-zero status. This is good.

However, if an ERR trap is called because a function returned a non-zero status, then ${BASH_SOURCE[0]} and ${FUNCNAME[0]} still indicate the file/function which called the function that returned a non-zero status, but $LINENO indicates the line number of the last command in the function that was called, and the line number of the call to the function is not available.

Example:
$ cat <<'END' >script1
test_fun() {
return 1
}
END
$ cat <<'END' >script2
#!/bin/bash
# Some blank lines to adjust the line numbers relative to script1

source script1
trap 'echo error at: ${BASH_SOURCE[0]} ${FUNCNAME[0]} $LINENO ${BASH_LINENO[@]}' ERR
false # Trigger the ERR trap with a command on line 6
test_fun # Trigger the ERR trap with a function on line 7
END
$ chmod 755 script2
$ ./script2
error at: ./script2 main 6 0
error at: ./script2 main 2 0
$

This seems like a bug. I would expect one of two behaviors here:
1) In the ERR trap on function return, $LINENO should point to the line which called the function (just as ${BASH_SOURCE[0]} and ${FUNCNAME[0]} point to the file/function which called the function that returned a non-zero status).
2) In the ERR trap on function return, ${BASH_SOURCE[0]}, ${FUNCNAME[0]}, and $LINENO should point to the last command executed within the function, and ${BASH_SOURCE[1]} ${FUNCNAME[1]} ${BASH_LINENO[0]} should point to the caller of the function.

Thoughts?

Thanks!

Paul Donohue <paulsd>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by chet (Updated the item)
  • -unavailable- added by paulsd (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 13 Nov 2015 06:11:36 PM UTCchetStatusNone=>Done

    Back to the top


    Powered by Savane 3.1-cleanup1