From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: Attaching context info to an error Date: Thu, 28 Dec 2023 07:57:16 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31211"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) 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 07:58:21 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 1rIkLV-0007x0-7Y for ged-emacs-devel@m.gmane-mx.org; Thu, 28 Dec 2023 07:58:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rIkKa-0001e6-0F; Thu, 28 Dec 2023 01:57:24 -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 1rIkKY-0001dj-D5 for emacs-devel@gnu.org; Thu, 28 Dec 2023 01:57:22 -0500 Original-Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rIkKW-0006Ho-M6 for emacs-devel@gnu.org; Thu, 28 Dec 2023 01:57:22 -0500 Original-Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-54c79968ffbso6034287a12.3 for ; Wed, 27 Dec 2023 22:57:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703746638; x=1704351438; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=3eEYNKmtH3YbYKxJnb8QWaqvfMF5IULKHEBTXIAs/r8=; b=TEsJMxW5l3QswtRuBiqfkpn8C4IU4ZsIo0VZgqhMrWpxhjIlqJyoHACvErmqlWDCxI ov6k12QNc6rdSoFj8mRaqkE+u3ErqZI05zOEc8OrVHbce6CAsAdWsQx5ddrsYiTsZwcR d8CI44XqqNwU/Webkd/zEPsvtFcHi33MzkYu0TXagQ4EnQHb3AwUxE0NID/cLBK00ZpA Y3YULWPf/FhN16bUZcSDKfaNAkr2VG4xrlCo1LohnkSQ9sBbL1HaFYqz/pI4EVej6Biv DaR0RXOM5uxYimWmjNZB7Gd+vjdQNK94gYfAQhC6cS1xdFi6ASiKTUG/amdO205I9x76 BSJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703746638; x=1704351438; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3eEYNKmtH3YbYKxJnb8QWaqvfMF5IULKHEBTXIAs/r8=; b=uwMbmK35wEhBzwCPJWjHTtMgSRicvil/ml4QYP2GNWBpHcF0Nd/Wk2b7VcFle8jYlh 5gvxhzZmUgEsCbvaohtsNLvP2Z9FnaqSdAYFtY+OB1ZDq2DQWKFetsBZIajOgJI71oaB wtw1XxiUriQDTcjVhqbLx4XIxX5yDrqba5dx4I06cDa5dFvnjBiZJ92yf1UwAK962dtF rS6Kh5xBl9uTaPxqyRyrv7x6U6K4a/7CLeRfbhPircnUGeJLG811tH2jM5f0D+c4MuNF SJyqpkAZbBm/6w0qDfzIdG5vRsF9holkd+cnJmg930g8R5oaBvaxuDWwMvvzG/SoCkaj A4Cw== X-Gm-Message-State: AOJu0YxosJSYaf+hOQ/FMPi+pI7rw97JJpVdqd8f03Xc3IaxNUKMhw33 A2TC8r4f/jPomwbUDgW8zHIGKiAkN1o= X-Google-Smtp-Source: AGHT+IEok5S0BAuwSYj5eWKWfsV64KB2xIwJLPx2rfMuoU1ZkezWvxbojJEIGbLjXKm7WJVdqAgI1Q== X-Received: by 2002:a17:906:80d1:b0:a26:88d4:b477 with SMTP id a17-20020a17090680d100b00a2688d4b477mr4234483ejx.111.1703746638177; Wed, 27 Dec 2023 22:57:18 -0800 (PST) Original-Received: from Pro.fritz.box (pd9e3637a.dip0.t-ipconnect.de. [217.227.99.122]) by smtp.gmail.com with ESMTPSA id a5-20020a1709062b0500b00a26e0174ae2sm4282468ejg.210.2023.12.27.22.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 22:57:17 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Fri, 22 Dec 2023 10:58:57 -0500") Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=gerd.moellmann@gmail.com; helo=mail-ed1-x52f.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:314269 Archived-At: Stefan Monnier writes: >>> The question is: where should we put this "context" info. >>> >>> One possibility is to do something like the following: >>> >>> (defun load (file ...) >>> (handler-bind ((error (lambda (err) >>> (signal 'error-during-load >>> (cons file err))))) >>> ...)) >> >> I'm just guessing - so the argument ERR of the handler function is not a >> `condition' object of some kind, in the CL sense? What is it? > > No, it's the same kind of objects as are bound to `err` in > (condition-case err ...), i.e. a cons of (ERROR-NAME . ERROR-DATA). > > I don't think it makes sense to have different kinds of objects for > `handler-bind` and for `condition-case`. WRT to "collecting dynamic context info". I don't know if the following is useful, it depends on what the context info is, but maybe it can serve as an inspiration? I was reading CMUCL code a bit today. CMUCL (and SBCL) do something like the below for handler-bind (and analogously for restart-bind): (defvar *handler-clusters* nil) (defmacro handler-bind (bindings &body forms) "(HANDLER-BIND ( {(type handler)}* ) body) Executes body in a dynamic context where the given handler bindings are in effect. Each handler must take the condition being signalled as an argument. The bindings are searched first to last in the event of a signalled condition." (unless (every #'(lambda (x) (and (listp x) (= (length x) 2))) bindings) (simple-program-error (intl:gettext "Ill-formed handler bindings."))) `(let ((*handler-clusters* (cons (list ,@(mapcar #'(lambda (x) `(cons ',(car x) ,(cadr x))) bindings)) *handler-clusters*))) (multiple-value-prog1 (progn ,@forms) ;; Wait for any float exceptions #+x87 (float-wait)))) Each handler-bind is associated with a binding of *handler-clusters*, which contains two things: the handlers of the handler-bind, and a link to the next such binding up the stack. (This chain is used to find handlers etc.). Maybe one could use such a construct in Emacs to additionally associate context with dynamic occurrances of handler-bind?