From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-0.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_GREY autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [IPv6:2a01:4f8:1c0c:6b10::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id DAC8B1F542 for ; Wed, 17 May 2023 02:04:05 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=mGiIbMvY; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sendgrid.net header.i=@sendgrid.net header.a=rsa-sha256 header.s=smtpapi header.b=F+WRHkfo; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id BA7EA7F426; Wed, 17 May 2023 02:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1684289034; bh=paA8xCUbFOBHV4eS3rblqffR+yZguqsoC34+x1SLmCk=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=mGiIbMvYwUY2kFGqGZesdF2iaL6ITQB1zN00oIMcjZMhp8MkIxH9aRVxE1FECX6+3 O/0g+ZtO4t7tLZehIiv5KFOd+6sFQBMN82mbepQ4Adtxr0ggXe7OwPqmi6vnqZTq3B QQ5kqQhRtEWJHLL4r145dmmBMCQpda9WLioKG61Y= Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 7EA3B7F400 for ; Wed, 17 May 2023 02:03:50 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (1024-bit key; unprotected) header.d=sendgrid.net header.i=@sendgrid.net header.a=rsa-sha256 header.s=smtpapi header.b=F+WRHkfo; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sendgrid.net; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=smtpapi; bh=NzzUo+URelzoNGZsVzsUTZLjiy/6JhP8K+KPTtjrOH4=; b=F+WRHkfoqTRi7tsMIR6+yusmi1rQrbcobgvFysKip2JO1j4kWNzRbd164v1ScZHeoyjh ymRLiK+i4Zj2XhxNQDzUsJVCns6ygnmBgTX3glL2WQCYgl3SAPZRCSKfi4+o0baZEe9Cau pSDwxEduBjH9EK/ywMQXB+z6W+/orIv9E= Received: by filterdrecv-d7bbbc8bf-qc8hg with SMTP id filterdrecv-d7bbbc8bf-qc8hg-1-64643604-19 2023-05-17 02:03:48.37253348 +0000 UTC m=+527035.498571870 Received: from herokuapp.com (unknown) by geopod-ismtpd-14 (SG) with ESMTP id fI9fSOpzQzu2YTc_d-bEjQ for ; Wed, 17 May 2023 02:03:48.337 +0000 (UTC) Date: Wed, 17 May 2023 02:03:48 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 18743 X-Redmine-Issue-Author: sos4nt X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: nobu X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 89929 X-SG-EID: =?us-ascii?Q?rA5eEsXeCy+asKowYcicHxhOSUaOWYD+XnPnBc7LFC9e0N1bioe3wf1SWvY2zT?= =?us-ascii?Q?RQi7CuYngTqev50HZmYo7EU3+MDUeFmwOLSDxTi?= =?us-ascii?Q?zwiW9jNHNhHjGypi5AQ4JQHrrdRUvIW7h+5aXtv?= =?us-ascii?Q?4tJEmsbat6iNd2eUfActPnbnA2Jkl0fh9s+tpQ=2F?= =?us-ascii?Q?SCsgYjCkimQIME0E8omMezQUiQhlaWb1BYOE7Kl?= =?us-ascii?Q?SLH4F646vGMJA8B=2FlKwQ2NxzgQtptBqNsCWMU1z?= =?us-ascii?Q?Mifh1gBveuTEYNruIvtKA=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: I4HWXCO4KV7SYLY4C325MHS26OKO2W7V X-Message-ID-Hash: I4HWXCO4KV7SYLY4C325MHS26OKO2W7V X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@sendgrid.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:113501] [Ruby master Bug#18743] Enumerator#next / peek re-use each others stacktraces List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "nobu (Nobuyoshi Nakada) via ruby-core" Cc: "nobu (Nobuyoshi Nakada)" Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Issue #18743 has been updated by nobu (Nobuyoshi Nakada). Seems find to me. One thing I concerned, `stop_exc` will be re-created every times, and no wa= y to know where it was first used up. How about chaining by `cause`? ```diff diff --git a/enumerator.c b/enumerator.c index b33c1713718..1cc8f9108cf 100644 --- a/enumerator.c +++ b/enumerator.c @@ -30,6 +30,9 @@ #include "internal/rational.h" #include "ruby/ruby.h" =20 +extern ID ruby_static_id_cause; +#define id_cause ruby_static_id_cause + /* * Document-class: Enumerator * @@ -787,8 +790,16 @@ get_next_values(VALUE obj, struct enumerator *e) { VALUE curr, vs; =20 - if (e->stop_exc) - rb_exc_raise(e->stop_exc); + if (e->stop_exc) { + VALUE exc =3D e->stop_exc; + VALUE result =3D rb_attr_get(exc, id_result); + VALUE mesg =3D rb_attr_get(exc, idMesg); + if (!NIL_P(mesg)) mesg =3D rb_str_dup(mesg); + VALUE stop_exc =3D rb_exc_new_str(rb_eStopIteration, mesg); + rb_ivar_set(stop_exc, id_result, result); + rb_ivar_set(stop_exc, id_cause, exc); + rb_exc_raise(stop_exc); + } =20 curr =3D rb_fiber_current(); =20 ``` In the test, save `$!` at the first `rescue` then `assert_same(cause, exc.c= ause)`. ---------------------------------------- Bug #18743: Enumerator#next / peek re-use each others stacktraces https://bugs.ruby-lang.org/issues/18743#change-103096 * Author: sos4nt (Stefan Sch=FC=DFler) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- I encountered an odd behavior. If I rescue the `StopIteration` exception from `peek` and call `next` after= wards: (or vice-versa) ```ruby # enum.rb # 1 # 2 enum =3D [].each # 3 enum.peek rescue nil # 4 enum.next # 5 ``` it will show the stacktrace from the rescued `peek` call: ``` $ ruby enum.rb enum.rb:4:in `peek': iteration reached an end (StopIteration) from enum.rb:4:in `
' ``` Whereas the error should refer to `next` on line number 5. The same happens when calling `peek` after `next` or when having muliple `p= eek` / `next` calls: ```ruby # enum.rb # 1 # 2 enum =3D [].each # 3 enum.peek rescue nil # 4 enum.next rescue nil # 5 enum.peek rescue nil # 6 puts "line #{__LINE__}" # 7 enum.next # 8 ``` The stacktrace from the first (rescued) `peek` or `next` call will be shown= which doesn't reflect the actual error location: ``` $ ruby enum.rb line 7 enum.rb:4:in `peek': iteration reached an end (StopIteration) from enum.rb:4:in `
' ``` This is very confusing when debugging code. ---Files-------------------------------- 01-Recreate-stacktrace-enumerator.patch (1.29 KB) --=20 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/postorius/lists/ruby-c= ore.ml.ruby-lang.org/