ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "ioquatix (Samuel Williams) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "ioquatix (Samuel Williams)" <noreply@ruby-lang.org>
Subject: [ruby-core:119734] [Ruby master Feature#20864] Support `error:` keyword to `Kernel#warn`
Date: Tue, 05 Nov 2024 15:04:02 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-110400.20241105150402.3344@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20864.20241105112127.3344@ruby-lang.org>

Issue #20864 has been updated by ioquatix (Samuel Williams).


> I wonder why error: in particular, and not just warn(text, **any_structured_metadata)?..

I'd be okay with that, in fact I was thinking of making that proposal but I wasn't sure it would be accepted if it was too general.

> Why not include the error directly in the warning message?

Good question! Unfortunately, I found that the formatting behaviour of `Warning.warn` is a bit problematic. The first argument to `Warning.warn` is a string concatenation of all arguments passed to `Kernel#warn`. Depending on the log output, I want to include the details of the error in a JSON format for structured logging. In order to do that, I need the original objects passed to `warn`. This includes adding trace metadata which may not be known about until later on in the output handling. However, I don't want to do that at the point of the call, as we don't know the output format at that point... it could be JSON, MessagePack, plain text, or some other format.

It may be the case that `warn` was not designed to be used that way, and I'm okay if that's the case. But I think this is a useful and generic extension point for logging. If we can allow extra meta-data (that can be ignored by default) to go via options, it significantly increases the usefulness of this interface - we can pick up those options in `Warning.warn` and use those to control the output accordingly.

----------------------------------------
Feature #20864: Support `error:` keyword to `Kernel#warn`
https://bugs.ruby-lang.org/issues/20864#change-110400

* Author: ioquatix (Samuel Williams)
* Status: Open
----------------------------------------
`Kernel#warn` is extremely useful.

It is possible to include some details about the current caller using `uplevel` for the current call stack. But it is not possible to include details about errors.

I'd like to propose another extension to log errors.

```ruby
begin
  # some work
rescue => error
  warn "An error occurred!", error: error
end
```

Such a feature would allow us to log errors using a standard interface.

I don't have an opinion about the implementation, but I wanted to get feedback on the interface.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

  parent reply	other threads:[~2024-11-05 15:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 11:21 [ruby-core:119726] " ioquatix (Samuel Williams) via ruby-core
2024-11-05 12:26 ` [ruby-core:119727] " zverok (Victor Shepelev) via ruby-core
2024-11-05 13:47 ` [ruby-core:119729] " Eregon (Benoit Daloze) via ruby-core
2024-11-05 15:04 ` ioquatix (Samuel Williams) via ruby-core [this message]
2024-11-05 16:14 ` [ruby-core:119742] " Dan0042 (Daniel DeLorme) via ruby-core
2024-11-05 22:05 ` [ruby-core:119754] " ioquatix (Samuel Williams) via ruby-core
2024-11-06 22:26 ` [ruby-core:119785] [Ruby master Feature#20864] Allow `Kernel#warn` to accept `**options` and pass these to `Warning.warn` ioquatix (Samuel Williams) via ruby-core
2024-11-06 23:38 ` [ruby-core:119786] " jeremyevans0 (Jeremy Evans) via ruby-core
2024-11-06 23:53 ` [ruby-core:119787] " ioquatix (Samuel Williams) via ruby-core
2024-11-07  1:26 ` [ruby-core:119788] " ioquatix (Samuel Williams) via ruby-core
2024-11-07  5:56 ` [ruby-core:119790] " ko1 (Koichi Sasada) via ruby-core
2024-11-07  6:09 ` [ruby-core:119791] " ioquatix (Samuel Williams) via ruby-core
2024-11-08  9:00 ` [ruby-core:119837] " shyouhei (Shyouhei Urabe) via ruby-core
2024-11-08 12:26 ` [ruby-core:119841] " Eregon (Benoit Daloze) via ruby-core

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-110400.20241105150402.3344@ruby-lang.org \
    --to=ruby-core@ml.ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).