Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update perlfunc.pod to document die newline workarounds #22037

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from

Conversation

jidanni
Copy link
Member

@jidanni jidanni commented Feb 27, 2024

Else the user cannot find where the program died!

Welcome to enhance my patch.

Else the user cannot find where the program died!

Welcome to enhance my patch.
@mauke
Copy link
Contributor

mauke commented Feb 27, 2024

What does a user care where a program died?

@jidanni
Copy link
Member Author

jidanni commented Feb 27, 2024

Because s/he might have 50 files, each with 50 die statements, and finding which one died would be a nightmare.

@guest20
Copy link

guest20 commented Feb 27, 2024

It's only a nightmare to find which die is which if your die messages don't contain unique/useful messages.

You really have two problems bumping up against each other here and it mostly goes away if, as a point of order, you include a label before you Dumper something to an output. Pick something unique so you can git grep for it.

I usually sub-class which ever logger the project uses with a labeled_dump method that dies if it doesn't get a label.

$app->log->labelled_dump( customer_credit_carrds => \@cards );
# Tue 27 [9203] request=b4dc0ffee [debug] customer_credit_cards [{type => amex....

Even in a single-file script using Data::Dumper directly is a bit of a pest, so I end up wrapping it in a similar sub (adding time, setting formatting etc)

@jidanni
Copy link
Member Author

jidanni commented Feb 28, 2024

The very very very very main source of problems, is the person way back one who thought it would be smart to make things act different depending on a final new line.

It might have seen like a cool idea way back when. But sure enough ...

Also one can I just use $. In here-documents, and then getting the file name is a big drag too.

So okay you guys are welcome to put your ideas into the die documentation too.

@guest20
Copy link

guest20 commented Feb 28, 2024

  1. Most programs don't include line numbers when showing error messages to users... Try ls --nonsense or docker evengreen or halt --hammerzeit

  2. die is how one raises exceptions, and you don't want line numbers in the string your callers get when catching and checking your exception.

  3. If you want to blame the caller for an exception (say when they pass invalid arguments) you need to be able to die without the site where you call die being in the message (like carp)

  4. Changing this behaviour breaks compat with existing code.

Maybe you can write a perlcritic role to prevent this being done on accident if your own code?

@jidanni
Copy link
Member Author

jidanni commented Feb 28, 2024

I don't want to change the code.

But workarounds should be documented for when
we want to keep getting the line numbers, despite
having a newline in our back pocket.

@Leont
Copy link
Contributor

Leont commented Feb 28, 2024

Yeah I don't think this is a good idea either

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants