all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "João Távora" <joaotavora@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Attaching context info to an error
Date: Fri, 29 Dec 2023 23:29:02 -0500	[thread overview]
Message-ID: <jwvv88gcpji.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CALDnm51h8P6grV7gPOu2kTXVMt1tfm5AinqHF9_xtmvcm5smBw@mail.gmail.com> ("João Távora"'s message of "Fri, 29 Dec 2023 17:29:26 +0000")

> Most importantly, and idea quality apart, who can be doing that
> today, before h-b?  No-one or practically no-one, since it's useless
> because currently the only place user code has access to
> the signal also unwinds the stack, and resignalling will make a new
> cons. Right?

Indeed, until now the identity of an error object can't be "noticed".
The only place other than the `condition-case` where an error can appear
is in `signal-hook-function` and this doesn't receive the error object
(it receives it in two pieces instead 🙁).

> So unless there's a specific use for it today,

Just because we can't think of a use case today doesn't mean there can't
be a good use case.  And yes, I do have some use cases.  Those use cases
may be able to use other approaches as well, but the various options all
have pros and cons.

> I recommend specifically _not_ maintaining 'eq'ness.
> This prevents people from making the job to transition to a non-cons
> representation of errors easier.

You lost me here.

>> We cannot reliably distinguish an error object from random other cons
>> cells, so things like `cl-print-object` are simply not an option: the
>> caller needs to tell us that this is an error object.
>> We could have a `print-error-object`, OTOH.
> Indeed this representation is really bothersome.

Actually, it's not.  We've lived with it quite happily for about 40
years now.  In practice, we really don't do much with error objects
other than re-signal them or pass them to `error-message-string`.

>> If it's only for resignaling purposes, why not have
>> `error-resignal` instead which takes the error object itself?
> This has to exist indeed.  Should be called "condition-resignal"
> though

Emacs's naming convention in this area is a bit murky, but I think it's
leaning towards `error` (e.g. the `error-message-string` function, the
`define-error` macro, the `error-conditions` and `error-message`
properties).
This said, as long as the new functions are nicely placed together in
their own namespace prefix, I'll be happy, so if you prefer
`condition-`, I can go along with that.

> (and the byte-compiler should warn you should use a
> handler-bind instead).

As I mentioned elsewhere, running code inside a `handler-bind` means
running in some arbitrary dynamic context, which can have surprising
effects because in ELisp dynvars influence the execution of a *lot* of
primitives (even `eq` is not immune).  So I don't think I can honestly
claim that re-signaling an error is almost always wrong.  Maybe with
more practice, I'll reach this conclusion, but I'm definitely not
there yet.  So, warning about resignaling seems premature.

>> I don't think we want to do that systematically, but yes (and I'm afraid
>> we'll discover along the way that the representations we use are messy
>> and don't always obey the subtyping suggested by the error hierarchy).
>> It presumably needs to come with a "similar" change on the constructor
>> side, so as long as we keep using (signal ERROR-TYPE ERROR-DATA) where
>> ERROR-DATA is a bare list it's not super pressing.
> I've also seen 0 examples so far where the DATA is searched inside
> for actual properties.

That's my impression as well.
The fact that the "data" part has no clearly defined shape (other than
being a list) means that it's used a bit "without purpose": I think that
in most cases, programmers put data in there only under the expectation
that it'll be useful when displayed in an error message or a backtrace.


        Stefan




  parent reply	other threads:[~2023-12-30  4:29 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-21 22:30 Attaching context info to an error Stefan Monnier
2023-12-22  6:50 ` Gerd Möllmann
2023-12-22  8:37   ` Gerd Möllmann
2023-12-22 15:58   ` Stefan Monnier
2023-12-28  6:57     ` Gerd Möllmann
2023-12-22 20:56 ` Jens Schmidt
2023-12-22 22:37   ` Stefan Monnier
2023-12-23  3:02 ` João Távora
2023-12-23  3:28   ` João Távora
2023-12-26 20:12     ` Stefan Monnier
2023-12-26 20:47   ` Stefan Monnier
2023-12-26 22:43     ` João Távora
2023-12-27  6:50       ` Gerd Möllmann
2023-12-27 10:29         ` João Távora
2023-12-27 10:35           ` Gerd Möllmann
2023-12-27 17:50       ` Stefan Monnier
2023-12-27 18:08         ` João Távora
2023-12-27 18:28           ` João Távora
2023-12-27 19:08           ` Stefan Monnier
2023-12-27 19:27             ` João Távora
2023-12-27 20:27               ` Stefan Monnier
2023-12-27 23:08                 ` João Távora
2023-12-28  7:05                   ` Stefan Monnier
2023-12-28 14:12                     ` João Távora
2023-12-28 16:03                       ` Stefan Monnier
2023-12-28 17:15                         ` João Távora
2023-12-28 19:22                           ` Stefan Monnier
2023-12-28 23:53                             ` João Távora
2023-12-29  2:54                               ` Stefan Monnier
2023-12-29  3:43                                 ` João Távora
2023-12-29 16:54                                   ` Stefan Monnier
2023-12-29 17:29                                     ` João Távora
2023-12-29 17:39                                       ` João Távora
2023-12-30  4:29                                       ` Stefan Monnier [this message]
2023-12-30 16:45                                         ` João Távora
2023-12-29 17:19                                   ` Alan Mackenzie
2023-12-29 17:24                                     ` João Távora
2023-12-29 17:43                                       ` Alan Mackenzie
2023-12-29 17:54                                         ` João Távora
2023-12-29 18:08                                           ` Alan Mackenzie
2023-12-29 18:45                                             ` João Távora
2023-12-29 18:35                                         ` Stefan Monnier
2023-12-29 18:48                                           ` João Távora

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=jwvv88gcpji.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@gmail.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.