diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2014-10-09 15:17:22 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2014-10-29 11:43:07 -0400 |
| commit | 7828c3dd2858d8f3a0448484d8093e22719dbda0 (patch) | |
| tree | 2d2b106b02526219463d877d480782027ffe1f3f /src/libstd/io/net | |
| parent | 3bc545373df4c81ba223a8bece14cbc27eb85a4d (diff) | |
| download | rust-7828c3dd2858d8f3a0448484d8093e22719dbda0.tar.gz rust-7828c3dd2858d8f3a0448484d8093e22719dbda0.zip | |
Rename fail! to panic!
https://github.com/rust-lang/rfcs/pull/221
The current terminology of "task failure" often causes problems when
writing or speaking about code. You often want to talk about the
possibility of an operation that returns a Result "failing", but cannot
because of the ambiguity with task failure. Instead, you have to speak
of "the failing case" or "when the operation does not succeed" or other
circumlocutions.
Likewise, we use a "Failure" header in rustdoc to describe when
operations may fail the task, but it would often be helpful to separate
out a section describing the "Err-producing" case.
We have been steadily moving away from task failure and toward Result as
an error-handling mechanism, so we should optimize our terminology
accordingly: Result-producing functions should be easy to describe.
To update your code, rename any call to `fail!` to `panic!` instead.
Assuming you have not created your own macro named `panic!`, this
will work on UNIX based systems:
grep -lZR 'fail!' . | xargs -0 -l sed -i -e 's/fail!/panic!/g'
You can of course also do this by hand.
[breaking-change]
Diffstat (limited to 'src/libstd/io/net')
| -rw-r--r-- | src/libstd/io/net/pipe.rs | 28 | ||||
| -rw-r--r-- | src/libstd/io/net/tcp.rs | 26 | ||||
| -rw-r--r-- | src/libstd/io/net/udp.rs | 32 |
3 files changed, 43 insertions, 43 deletions
diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/io/net/pipe.rs index e0cf761fdbd..112094d1d39 100644 --- a/src/libstd/io/net/pipe.rs +++ b/src/libstd/io/net/pipe.rs @@ -269,13 +269,13 @@ mod tests { spawn(proc() { match UnixStream::connect(&path2) { Ok(c) => client(c), - Err(e) => fail!("failed connect: {}", e), + Err(e) => panic!("failed connect: {}", e), } }); match acceptor.accept() { Ok(c) => server(c), - Err(e) => fail!("failed accept: {}", e), + Err(e) => panic!("failed accept: {}", e), } } @@ -283,7 +283,7 @@ mod tests { fn bind_error() { let path = "path/to/nowhere"; match UnixListener::bind(&path) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => { assert!(e.kind == PermissionDenied || e.kind == FileNotFound || e.kind == InvalidInput); @@ -299,7 +299,7 @@ mod tests { "path/to/nowhere" }; match UnixStream::connect(&path) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => { assert!(e.kind == FileNotFound || e.kind == OtherIoError); } @@ -358,7 +358,7 @@ mod tests { let mut acceptor = match UnixListener::bind(&path1).listen() { Ok(a) => a, - Err(e) => fail!("failed listen: {}", e), + Err(e) => panic!("failed listen: {}", e), }; spawn(proc() { @@ -366,7 +366,7 @@ mod tests { let mut stream = UnixStream::connect(&path2); match stream.write([100]) { Ok(..) => {} - Err(e) => fail!("failed write: {}", e) + Err(e) => panic!("failed write: {}", e) } } }); @@ -376,7 +376,7 @@ mod tests { let mut buf = [0]; match client.read(buf) { Ok(..) => {} - Err(e) => fail!("failed read/accept: {}", e), + Err(e) => panic!("failed read/accept: {}", e), } assert_eq!(buf[0], 100); } @@ -531,10 +531,10 @@ mod tests { match a.accept() { Ok(..) => break, Err(ref e) if e.kind == TimedOut => {} - Err(e) => fail!("error: {}", e), + Err(e) => panic!("error: {}", e), } ::task::deschedule(); - if i == 1000 { fail!("should have a pending connection") } + if i == 1000 { panic!("should have a pending connection") } } drop(l); @@ -659,9 +659,9 @@ mod tests { match s.write([0, .. 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } - if i == 1000 { fail!("should have filled up?!"); } + if i == 1000 { panic!("should have filled up?!"); } } // I'm not sure as to why, but apparently the write on windows always @@ -687,7 +687,7 @@ mod tests { while amt < 100 * 128 * 1024 { match s.read([0, ..128 * 1024]) { Ok(n) => { amt += n; } - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } } let _ = rx.recv_opt(); @@ -722,9 +722,9 @@ mod tests { match s.write([0, .. 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } - if i == 1000 { fail!("should have filled up?!"); } + if i == 1000 { panic!("should have filled up?!"); } } tx.send(()); diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index d6528ce977e..09804ef5703 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -471,7 +471,7 @@ impl TcpAcceptor { /// match socket { /// Ok(s) => { /* handle s */ } /// Err(ref e) if e.kind == EndOfFile => break, // closed - /// Err(e) => fail!("unexpected error: {}", e), + /// Err(e) => panic!("unexpected error: {}", e), /// } /// } /// }); @@ -532,7 +532,7 @@ mod test { #[test] fn bind_error() { match TcpListener::bind("0.0.0.0", 1) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, PermissionDenied), } } @@ -540,7 +540,7 @@ mod test { #[test] fn connect_error() { match TcpStream::connect("0.0.0.0", 1) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, ConnectionRefused), } } @@ -708,7 +708,7 @@ mod test { assert!(nread.is_err()); match stream.read(buf) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(ref e) => { assert!(e.kind == NotConnected || e.kind == EndOfFile, "unknown kind: {}", e.kind); @@ -734,7 +734,7 @@ mod test { assert!(nread.is_err()); match stream.read(buf) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(ref e) => { assert!(e.kind == NotConnected || e.kind == EndOfFile, "unknown kind: {}", e.kind); @@ -1082,7 +1082,7 @@ mod test { let listener = TcpListener::bind(ip_str.as_slice(), port).unwrap().listen(); assert!(listener.is_ok()); match TcpListener::bind(ip_str.as_slice(), port).listen() { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => { assert!(e.kind == ConnectionRefused || e.kind == OtherIoError, "unknown error: {} {}", e, e.kind); @@ -1266,10 +1266,10 @@ mod test { match a.accept() { Ok(..) => break, Err(ref e) if e.kind == TimedOut => {} - Err(e) => fail!("error: {}", e), + Err(e) => panic!("error: {}", e), } ::task::deschedule(); - if i == 1000 { fail!("should have a pending connection") } + if i == 1000 { panic!("should have a pending connection") } } } @@ -1373,9 +1373,9 @@ mod test { match s.write([0, .. 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } - if i == 1000 { fail!("should have filled up?!"); } + if i == 1000 { panic!("should have filled up?!"); } } assert_eq!(s.write([0]).err().unwrap().kind, TimedOut); @@ -1398,7 +1398,7 @@ mod test { while amt < 100 * 128 * 1024 { match s.read([0, ..128 * 1024]) { Ok(n) => { amt += n; } - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } } let _ = rx.recv_opt(); @@ -1435,9 +1435,9 @@ mod test { match s.write([0, .. 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } - if i == 1000 { fail!("should have filled up?!"); } + if i == 1000 { panic!("should have filled up?!"); } } assert_eq!(s.write([0]).err().unwrap().kind, TimedOut); diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 7d9eea3a732..ad9ed090a5b 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -43,7 +43,7 @@ use rt::rtio; /// let addr = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 34254 }; /// let mut socket = match UdpSocket::bind(addr) { /// Ok(s) => s, -/// Err(e) => fail!("couldn't bind socket: {}", e), +/// Err(e) => panic!("couldn't bind socket: {}", e), /// }; /// /// let mut buf = [0, ..10]; @@ -271,7 +271,7 @@ mod test { fn bind_error() { let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; match UdpSocket::bind(addr) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, PermissionDenied), } } @@ -289,7 +289,7 @@ mod test { rx1.recv(); client.send_to([99], server_ip).unwrap() } - Err(..) => fail!() + Err(..) => panic!() } tx2.send(()); }); @@ -304,10 +304,10 @@ mod test { assert_eq!(buf[0], 99); assert_eq!(src, client_ip); } - Err(..) => fail!() + Err(..) => panic!() } } - Err(..) => fail!() + Err(..) => panic!() } rx2.recv(); } @@ -324,7 +324,7 @@ mod test { rx.recv(); client.send_to([99], server_ip).unwrap() } - Err(..) => fail!() + Err(..) => panic!() } }); @@ -338,10 +338,10 @@ mod test { assert_eq!(buf[0], 99); assert_eq!(src, client_ip); } - Err(..) => fail!() + Err(..) => panic!() } } - Err(..) => fail!() + Err(..) => panic!() } } @@ -362,7 +362,7 @@ mod test { let mut stream = client.connect(server_ip); stream.write(val).unwrap(); } - Err(..) => fail!() + Err(..) => panic!() } }; rx1.recv(); @@ -382,10 +382,10 @@ mod test { assert_eq!(nread, 1); assert_eq!(buf[0], 99); } - Err(..) => fail!(), + Err(..) => panic!(), } } - Err(..) => fail!() + Err(..) => panic!() } rx2.recv(); } @@ -406,7 +406,7 @@ mod test { rx1.recv(); stream.write([99]).unwrap(); } - Err(..) => fail!() + Err(..) => panic!() } tx2.send(()); }); @@ -422,10 +422,10 @@ mod test { assert_eq!(nread, 1); assert_eq!(buf[0], 99); } - Err(..) => fail!() + Err(..) => panic!() } } - Err(..) => fail!() + Err(..) => panic!() } rx2.recv(); } @@ -535,7 +535,7 @@ mod test { rx.recv(); match sock2.recv_from(buf) { Ok(..) => {} - Err(e) => fail!("failed receive: {}", e), + Err(e) => panic!("failed receive: {}", e), } serv_tx.send(()); }); @@ -612,7 +612,7 @@ mod test { match a.send_to([0, ..4*1024], addr2) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("other error: {}", e), + Err(e) => panic!("other error: {}", e), } } } |
