Skip to content

Commit 0fdef81

Browse files
authored
Merge branch 'master' into bundled_bigdecimal
2 parents 64b3699 + 54d3945 commit 0fdef81

File tree

6 files changed

+90
-13
lines changed

6 files changed

+90
-13
lines changed

NEWS.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ Note: We're only listing outstanding class updates.
9898
`Binding#implicit_parameter_defined?` have been added to access
9999
numbered parameters and "it" parameter. [[Bug #21049]]
100100
101+
* ErrorHighlight
102+
103+
* When an ArgumentError is raised, it now displays code snippets for
104+
both the method call (caller) and the method definition (callee).
105+
[[Feature #21543]]
106+
107+
```
108+
test.rb:1:in 'Object#add': wrong number of arguments (given 1, expected 2) (ArgumentError)
109+
110+
caller: test.rb:3
111+
| add(1)
112+
^^^
113+
callee: test.rb:1
114+
| def add(x, y) = x + y
115+
^^^
116+
from test.rb:3:in '<main>'
117+
```
118+
101119
* File
102120
103121
* `File::Stat#birthtime` is now available on Linux via the statx
@@ -347,6 +365,31 @@ The following bundled gems are updated.
347365
and was already deprecated,.
348366
[[Feature #20971]]
349367

368+
* A backtrace for `ArgumentError` of "wrong number of arguments" now
369+
include the receiver's class or module name (e.g., in `Foo#bar`
370+
instead of in `bar`). [[Bug #21698]]
371+
372+
* Backtraces no longer display `internal` frames.
373+
These methods now appear as if it is in the Ruby source file,
374+
consistent with other C-implemented methods. [[Bug #20968]]
375+
376+
Before:
377+
```
378+
ruby -e '[1].fetch_values(42)'
379+
<internal:array>:211:in 'Array#fetch': index 42 outside of array bounds: -1...1 (IndexError)
380+
from <internal:array>:211:in 'block in Array#fetch_values'
381+
from <internal:array>:211:in 'Array#map!'
382+
from <internal:array>:211:in 'Array#fetch_values'
383+
from -e:1:in '<main>'
384+
```
385+
386+
After:
387+
```
388+
$ ruby -e '[1].fetch_values(42)'
389+
-e:1:in 'Array#fetch_values': index 42 outside of array bounds: -1...1 (IndexError)
390+
from -e:1:in '<main>'
391+
```
392+
350393
## Stdlib compatibility issues
351394

352395
* CGI library is removed from the default gems. Now we only provide `cgi/escape` for
@@ -446,6 +489,7 @@ A lot of work has gone into making Ractors more stable, performant, and usable.
446489
[Feature #20750]: https://bugs.ruby-lang.org/issues/20750
447490
[Feature #20884]: https://bugs.ruby-lang.org/issues/20884
448491
[Feature #20925]: https://bugs.ruby-lang.org/issues/20925
492+
[Bug #20968]: https://bugs.ruby-lang.org/issues/20968
449493
[Feature #20971]: https://bugs.ruby-lang.org/issues/20971
450494
[Bug #20974]: https://bugs.ruby-lang.org/issues/20974
451495
[Feature #21047]: https://bugs.ruby-lang.org/issues/21047
@@ -470,8 +514,10 @@ A lot of work has gone into making Ractors more stable, performant, and usable.
470514
[Feature #21390]: https://bugs.ruby-lang.org/issues/21390
471515
[Feature #21459]: https://bugs.ruby-lang.org/issues/21459
472516
[Feature #21527]: https://bugs.ruby-lang.org/issues/21527
517+
[Feature #21543]: https://bugs.ruby-lang.org/issues/21543
473518
[Feature #21550]: https://bugs.ruby-lang.org/issues/21550
474519
[Feature #21557]: https://bugs.ruby-lang.org/issues/21557
475520
[Bug #21654]: https://bugs.ruby-lang.org/issues/21654
476521
[Feature #21678]: https://bugs.ruby-lang.org/issues/21678
522+
[Bug #21698]: https://bugs.ruby-lang.org/issues/21698
477523
[Feature #21701]: https://bugs.ruby-lang.org/issues/21701

ext/socket/init.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ rsock_socket(int domain, int type, int proto)
473473

474474
/* emulate blocking connect behavior on EINTR or non-blocking socket */
475475
static int
476-
wait_connectable(VALUE self, VALUE timeout)
476+
wait_connectable(VALUE self, VALUE timeout, const struct sockaddr *sockaddr, int len)
477477
{
478478
int sockerr;
479479
socklen_t sockerrlen;
@@ -514,7 +514,10 @@ wait_connectable(VALUE self, VALUE timeout)
514514
VALUE result = rb_io_wait(self, RB_INT2NUM(RUBY_IO_READABLE|RUBY_IO_WRITABLE), timeout);
515515

516516
if (result == Qfalse) {
517-
rb_raise(rb_eIOTimeoutError, "Connect timed out!");
517+
VALUE rai = rsock_addrinfo_new((struct sockaddr *)sockaddr, len, PF_UNSPEC, 0, 0, Qnil, Qnil);
518+
VALUE addr_str = rsock_addrinfo_inspect_sockaddr(rai);
519+
VALUE message = rb_sprintf("user specified timeout for %" PRIsVALUE, addr_str);
520+
rb_raise(rb_eIOTimeoutError, "%" PRIsVALUE, message);
518521
}
519522

520523
int revents = RB_NUM2INT(result);
@@ -603,7 +606,7 @@ rsock_connect(VALUE self, const struct sockaddr *sockaddr, int len, int socks, V
603606
#ifdef EINPROGRESS
604607
case EINPROGRESS:
605608
#endif
606-
return wait_connectable(self, timeout);
609+
return wait_connectable(self, timeout, sockaddr, len);
607610
}
608611
}
609612
return status;

ext/socket/ipsocket.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ struct inetsock_arg
2727
};
2828

2929
void
30-
rsock_raise_user_specified_timeout(void)
30+
rsock_raise_user_specified_timeout(struct addrinfo *ai, VALUE host, VALUE port)
3131
{
32-
rb_raise(rb_eIOTimeoutError, "user specified timeout");
32+
VALUE message;
33+
34+
if (ai && ai->ai_addr) {
35+
VALUE rai = rsock_addrinfo_new((struct sockaddr *)ai->ai_addr, (socklen_t)ai->ai_addrlen, PF_UNSPEC, 0, 0, Qnil, Qnil);
36+
VALUE addr_str = rsock_addrinfo_inspect_sockaddr(rai);
37+
message = rb_sprintf("user specified timeout for %" PRIsVALUE, addr_str);
38+
} else {
39+
message = rb_sprintf("user specified timeout for %" PRIsVALUE " port %" PRIsVALUE, host, port);
40+
}
41+
42+
rb_raise(rb_eIOTimeoutError, "%" PRIsVALUE, message);
3343
}
3444

3545
static VALUE
@@ -149,7 +159,9 @@ init_inetsock_internal(VALUE v)
149159
} else {
150160
VALUE elapsed = rb_funcall(current_clocktime(), '-', 1, starts_at);
151161
timeout = rb_funcall(open_timeout, '-', 1, elapsed);
152-
if (rb_funcall(timeout, '<', 1, INT2FIX(0)) == Qtrue) rsock_raise_user_specified_timeout();
162+
if (rb_funcall(timeout, '<', 1, INT2FIX(0)) == Qtrue) {
163+
rsock_raise_user_specified_timeout(res, arg->remote.host, arg->remote.serv);
164+
}
153165
}
154166

155167
if (status >= 0) {
@@ -844,6 +856,10 @@ init_fast_fallback_inetsock_internal(VALUE v)
844856
if (!NIL_P(open_timeout)) {
845857
VALUE elapsed = rb_funcall(current_clocktime(), '-', 1, starts_at);
846858
timeout = rb_funcall(open_timeout, '-', 1, elapsed);
859+
860+
if (rb_funcall(timeout, '<', 1, INT2FIX(0)) == Qtrue) {
861+
rsock_raise_user_specified_timeout(NULL, arg->remote.host, arg->remote.serv);
862+
}
847863
}
848864
if (NIL_P(timeout)) {
849865
if (!NIL_P(connect_timeout)) {
@@ -1180,7 +1196,9 @@ init_fast_fallback_inetsock_internal(VALUE v)
11801196
}
11811197
}
11821198

1183-
if (is_timeout_tv(user_specified_open_timeout_at, now)) rsock_raise_user_specified_timeout();
1199+
if (is_timeout_tv(user_specified_open_timeout_at, now)) {
1200+
rsock_raise_user_specified_timeout(NULL, arg->remote.host, arg->remote.serv);
1201+
}
11841202

11851203
if (!any_addrinfos(&resolution_store)) {
11861204
if (!in_progress_fds(arg->connection_attempt_fds_size) &&
@@ -1203,7 +1221,7 @@ init_fast_fallback_inetsock_internal(VALUE v)
12031221
resolution_store.is_all_finished) &&
12041222
(is_timeout_tv(user_specified_connect_timeout_at, now) ||
12051223
!in_progress_fds(arg->connection_attempt_fds_size))) {
1206-
rsock_raise_user_specified_timeout();
1224+
rsock_raise_user_specified_timeout(NULL, arg->remote.host, arg->remote.serv);
12071225
}
12081226
}
12091227
}

ext/socket/lib/socket.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def connect_internal(local_addrinfo, timeout=nil) # :yields: socket
6262
break
6363
when :wait_writable
6464
sock.wait_writable(timeout) or
65-
raise Errno::ETIMEDOUT, 'user specified timeout'
65+
raise Errno::ETIMEDOUT, "user specified timeout for #{self.ip_address}:#{self.ip_port}"
6666
end while true
6767
else
6868
sock.connect(self)
@@ -905,7 +905,9 @@ def self.tcp_with_fast_fallback(host, port, local_host = nil, local_port = nil,
905905
end
906906
end
907907

908-
raise(IO::TimeoutError, 'user specified timeout') if expired?(now, user_specified_open_timeout_at)
908+
if expired?(now, user_specified_open_timeout_at)
909+
raise(IO::TimeoutError, "user specified timeout for #{host}:#{port}")
910+
end
909911

910912
if resolution_store.empty_addrinfos?
911913
if connecting_sockets.empty? && resolution_store.resolved_all_families?
@@ -918,7 +920,7 @@ def self.tcp_with_fast_fallback(host, port, local_host = nil, local_port = nil,
918920

919921
if (expired?(now, user_specified_resolv_timeout_at) || resolution_store.resolved_all_families?) &&
920922
(expired?(now, user_specified_connect_timeout_at) || connecting_sockets.empty?)
921-
raise IO::TimeoutError, 'user specified timeout'
923+
raise(IO::TimeoutError, "user specified timeout for #{host}:#{port}")
922924
end
923925
end
924926
end

ext/socket/raddrinfo.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,15 @@ rb_getaddrinfo(const char *hostp, const char *portp, const struct addrinfo *hint
597597

598598
if (need_free) free_getaddrinfo_arg(arg);
599599

600-
if (timedout) rsock_raise_user_specified_timeout();
600+
if (timedout) {
601+
if (arg->ai) {
602+
rsock_raise_user_specified_timeout(arg->ai, Qnil, Qnil);
603+
} else {
604+
VALUE host = rb_str_new_cstr(hostp);
605+
VALUE port = rb_str_new_cstr(portp);
606+
rsock_raise_user_specified_timeout(NULL, host, port);
607+
}
608+
}
601609

602610
// If the current thread is interrupted by asynchronous exception, the following raises the exception.
603611
// But if the current thread is interrupted by timer thread, the following returns; we need to manually retry.

ext/socket/rubysocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ void free_fast_fallback_getaddrinfo_shared(struct fast_fallback_getaddrinfo_shar
454454
#endif
455455

456456
unsigned int rsock_value_timeout_to_msec(VALUE);
457-
NORETURN(void rsock_raise_user_specified_timeout(void));
457+
NORETURN(void rsock_raise_user_specified_timeout(struct addrinfo *ai, VALUE host, VALUE port));
458458

459459
void rsock_init_basicsocket(void);
460460
void rsock_init_ipsocket(void);

0 commit comments

Comments
 (0)