[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to make "division by zero attempted" error message more informat
From: |
Peng Yu |
Subject: |
Re: How to make "division by zero attempted" error message more informative? |
Date: |
Thu, 3 Mar 2022 17:58:08 -0600 |
This sounds like a reasonably good way to allow awk to support
customizable error messages for locating the awk code inlined in shell
scripts.
On 3/3/22, Andrew J. Schorr <aschorr@telemetry-investments.com> wrote:
> On Thu, Mar 03, 2022 at 01:55:23PM -0600, Neil R. Ormos wrote:
>> There is no magic way for Gawk to know what should be printed in the error
>> message to distinguish a particular call.
>
> Well, the truth is that it wouldn't be hard to add such a feature. When gawk
> starts up,
> it parses the name by which it was invoked to extract the name to use at the
> start
> of error messages:
>
> const char *myname;
> ...
> int
> main(int argc, char **argv)
> {
> ...
> myname = gawk_name(argv[0]);
>
> So it would be fairly simple to add an environment variable to override
> this.
> For example, one might test for an environment variable "GAWK_ERROR_NAME"
> and use that instead if present and not empty:
>
> if (!(myname = getenv("GAWK_ERROR_NAME")) || !*myname)
> myname = gawk_name(argv[0]);
>
> Now whether to patch the code in that fashion is a good idea is an entirely
> different question. But anybody who needs that feature can easily
> apply this patch. Or one could add a command-line option to accomplish
> the same thing.
>
> bash-4.2$ GAWK_ERROR_NAME=fubar ./gawk 'BEGIN {print 10/0}'
> fubar: cmd. line:1: error: division by zero attempted
> bash-4.2$
>
> Regards,
> Andy
>
--
Regards,
Peng
Re: How to make "division by zero attempted" error message more informative?, Neil R. Ormos, 2022/03/03