From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: Attaching context info to an error Date: Wed, 27 Dec 2023 23:08:41 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36454"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 28 00:09:38 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rId1u-0009Il-HR for ged-emacs-devel@m.gmane-mx.org; Thu, 28 Dec 2023 00:09:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rId1H-0000OH-N9; Wed, 27 Dec 2023 18:08:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rId1G-0000O6-2N for emacs-devel@gnu.org; Wed, 27 Dec 2023 18:08:58 -0500 Original-Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rId1E-0007bN-66 for emacs-devel@gnu.org; Wed, 27 Dec 2023 18:08:57 -0500 Original-Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2ccc80791e1so22120621fa.1 for ; Wed, 27 Dec 2023 15:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703718534; x=1704323334; darn=gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ceEndANqtqq/1SFE5r6fqK0Ib1STSR3nIk+0qxOSS7o=; b=BXcgRZazuSKfKN/dWwjqdHevBvdbswStBw/gWTNaR7d6mPmVIeovyGb0bOzo3TY6pt uUtW9MdtdLYSJSHkgOC9zXC1iCX6XcRmIXs3XuxzTy+UxpERuDwcR3j0JrZREzZquBZh +28z4Ez+St/Wp//ICZqdQvX6jib9zP4MAcxJ0m/H9cKmhjE9fXHMApwdPLLkPfiWaMRi BEF2e8wWwVBV/FQxwWVbrSgfaM6My4Ya3L1Y9moqluJdkZkEpGMvz35rY68ZFphPJS2q C8ossgnLymYf0cyMBIIO6B0qujbWhPkj1BZ/Pu+3UttO0H3iU8AsM+auNi1oGzyrBQbO gjew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703718534; x=1704323334; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ceEndANqtqq/1SFE5r6fqK0Ib1STSR3nIk+0qxOSS7o=; b=IpRHamyuGDq9wAK4310Q/TwLH/o2s4L8PUcd+g7OENGTCBzGLCxpJI7czLILm64l7U TdZc56h8a5yuB9/llXtn7doxm+//lcXfQKMZFRKTAEkqmEXhEGTNNuRyuL7/pcIOnVUk xCvbQYRkxaqHmiQBxCzkYGMxJj/9TA9ccClaWNprkggpVxRsiYv48Htys8+a7xayuMoM nKl60fLquS/XNFEvEGDHkQDmBbvZflITeb/bXf7j/sJ2LLQn+ONeQtgRuPzgMs4Aj/vh NdHaGP86ggHDhJSXJh+dv8+1I/f6dRJrpsXF37fvLgXnLfIOSPJYPWuvh20pY+UhlAXa jdWQ== X-Gm-Message-State: AOJu0YwpftV8fWmU7pwA5EsplCshP+kJZO4+QCaIH4KbIlswqM7CQMws 9p7jiqq35KMxflG8Gl4thIgxXYtjghjLbpTt1gompvVSKuU= X-Google-Smtp-Source: AGHT+IH4aE+Xz96sHIJmROr7bv4sWrBgChF3mY+sg9V14OCmDOeb1DbFqPtU73/J4vCh8Mx6FTCBDb+Sg/7J/9KgLxU= X-Received: by 2002:a2e:5cc9:0:b0:2cc:a5a3:cf50 with SMTP id q192-20020a2e5cc9000000b002cca5a3cf50mr5674174ljb.8.1703718533453; Wed, 27 Dec 2023 15:08:53 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=joaotavora@gmail.com; helo=mail-lj1-x232.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:314263 Archived-At: On Wed, Dec 27, 2023 at 8:27=E2=80=AFPM Stefan Monnier wrote: > > >> [ Not clear what `initialize-instance` would be used for. > > It is passed the keyword arguments that are passed to CL:ERROR > > or CL:SIGNAL [1,2]. > > Yes, I know, but that doesn't tell me what it lets us do that we can't > do right now. I guess we can do everything with symbol and cons, it's just more work. I'd guess the cl-averse are still doing structs with vectors :-= ) > > > Though, I've noted before how our initialize-instance protocol > > is inferior: It takes slots as its second argument, whereas is > > should take initargs instead. This makes changing the > > representation without changing the interface hard, but that > > can be worked around with the slot-missing protocol. > > [ While Eric called it "slots" it holds the plist of initargs, just > like the CLOS one. The only difference I know is that CLOS passes it a= s > an `&rest` arg. Yes, but it's a big one. Out versionwill go looking for slots for that each initarg and if the slot doesn't exist it barfs, whereas in Common Lisp you can make it &accept-other-keys. I think I also wrote about this off list. In CL, make-instance can be given arbitrary keyword args and they will show up in the initialize-instance. They may or may not line up with a slot's initarg. This enables us to change the data representation while keeping the interface to the class. See the current master's lisp/jsonrpc.el for an example where I had to use slot-missing to get around this. > You also told me that CLOS includes the "default" init > args taken from the `defclass`, but I'm not familiar with > those details (neither for CLOS nor for EIEIO). ] Also that. > >> I also don't think `print-object` would be super useful, > > It's useful when printing the human-readable error message isn't > > appropriate say, because it takes multiple lines. > > I'm not sure the difference qualifies as "super useful". > I don't mean to say we wouldn't be happy to be able to define ad-hoc > methods for `cl-print-object` of error objects, but it's much too minor > to motivate a change of representation. You don't even have to define anything. The cl-print-object of any EIEIO object is acceptable as a start. A more advanced version will do stuff with the objects 'format-control' and 'format-arguments', respecting print-escape and print-readably. > >> More importantly, that doesn't tell me what new things we could do, > >> most importantly how to attach context info :-) > > You can modify a condition object like you can any other > > object. > > I'm afraid that doesn't tell me how to attach context to an > error object. The context I'm talking about are orthogonal to the error > objects themselves: any kind of context info could be attached to any > kind of error object. I don't know what "context" you are talking about (I guess it was in the initial email, but I couldn't grok it). A setf-able condition-context generic sounds fair to me tho. Maybe start with an external representation in a weak-keyed hash table, then move it to a slot in the top of the hierarchy? > I guess the only way this would help is if we had the foresight, when > designing the root class for error objects, to include a `context` slot > (even though it might go unused most of the time). > Is that what you had in mind? Ah, yes! Read above, great minds... as usual ;-) > What I mean is that if we start using something else than cons cells to > represent error objects, loads of code will break because of things like: > > (condition-case err > ... > (error ... (signal (car err) (cdr err)))) Ugh indeed. 40 years of leaky abstractions, =C2=AF\_(=E3=83=84)_/=C2=AF So yes, "error" err would have that poor man's cons. Maybe condition-case would only catch those? A new shiny handler-case on the other hand, would catch proper richie rich errors (and have the better syntax). Or maybe do some other syntax trick? (condition-case err ... (error ((e)) ... ); 'err' is that strange cons, 'e' is a proper condition (warning ((w)) ... ); ditto for 'err' and w. ) I'm sure you can come up with better tho :-) Jo=C3=A3o