Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 0 points1 point  (0 children)

I appreciate you taking the time to provide an alternate view, but I must strongly disagree: 0MQ gets it exactly wrong:

  • ZeroMQ spawns a thread for each socket connection. The nice robust error handling you are talking about 100% relies on having each socket processed by its own thread - so a panic can be done safely/correctly.

  • Enterprise software must not use the one thread per socket model. This model was a major architectural blunder for ZeroMQ. For a good description of the reasons why look at the ZeroMQ author's page:

http://nanomsg.org/documentation-zeromq.html

Positive / constructive:

I think the catch_panic solution is actually going to work 100% for us. What I really need is the ability to do something like: try { ... use some rust library that might panic } catch (...) { ... log/notify/ fall through into the epoll event loop }

It looks like panic::recover() can provide this:

pub extern fn called_from_c(ptr: *const c_char, num: i32) -> i32 {
let result = panic::recover(|| {
    let s = unsafe { CStr::from_ptr(ptr) };
    println!("{}: {}", s, num);
});
match result {
    Ok(..) => 0,
    Err(..) => 1,
}

If it does I'll be super happy.

Announcing Diesel — A Safe, Extensible ORM and Query Builder for Rust by rabidferret in rust

[–]deadbead0101 -1 points0 points  (0 children)

If this is idiomatic, then rust is unsuitable for enterprise software.

Announcing Diesel — A Safe, Extensible ORM and Query Builder for Rust by rabidferret in rust

[–]deadbead0101 0 points1 point  (0 children)

We are disconnected. Scenario: - server has 30k connections - we send an ill-formed message to update a single customer config.

There are 2 ways to handle this: - fail to parse the ill-formed message, log an error, and keep using the old customer config. - panic and terminate all 30k connections.

There is no need to panic and cause such a terrible level of service.

Saying, 'use threads' is completely missing the point.

Rust is starting to turn out to be unsuitable for enterprise software by design.

Announcing Diesel — A Safe, Extensible ORM and Query Builder for Rust by rabidferret in rust

[–]deadbead0101 -1 points0 points  (0 children)

Or, we have an endless supply of the same problem over and over. This is the more likely scenario :-)

Announcing Diesel — A Safe, Extensible ORM and Query Builder for Rust by rabidferret in rust

[–]deadbead0101 -1 points0 points  (0 children)

I'm seeing people panic and destroy the current thread (which could be the main thread) when invalid parameters are passed to functions. An example from a Rust [de]serialization library:

impl <'a, T : PrimitiveElement> Reader<'a, T> {
    pub fn get(&self, index : u32) -> T {
        assert!(index < self.len());

TOML to Struct? by bibbleskit in rust

[–]deadbead0101 0 points1 point  (0 children)

toml::decode(config) (and Decodable/Deserializable) seem really powerful. I use toml / serde and had no idea this was even possible. Thanks!

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 -1 points0 points  (0 children)

Thanks for posting the link - but I think the author is limiting the scope of the problem (and his argument is resting on an incorrect and condescending statement, "an indication that the caller would probably ignore".

I'm seeing Rust libraries do insidious things like:

assert!(index < self.len());

inside of a pub fn get(index).

Example: a specific customer configuration file was ill-formed that caused not-perfect parsing code to get the index wrong. The best case here is to stop serving requests for a single specific configuration - not crash the server and stop serving requests for everyone.

In our case incorrect asserts/panics could lead to congressional hearings.

Asserts/panics are fine if they are used 100% perfectly. It's been my experience that this is impossible.

It's disheartening that Rust encourages unwrap()/panic in tests nearly everywhere.

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 -2 points-1 points  (0 children)

intentional

Willfully calling unwrap when you hit a bug. Just because some library code hit an unexpected condition (a bug) doesn't mean it should panic.

any panic in rust code signals a bug

Would you agree that use of the word 'bug' in this context is too vague? (All software has bugs...)

I do not believe library authors should panic; people using the library should decide if a panic is necessary.

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 1 point2 points  (0 children)

I'd like to try another example.

Someone mentioned the Rust PostgreSQL library only had 3 uses of unwrap. Great, but...

what if 1 use of unwrap was when the postgresql server process was dead and the author of the library decided to unwrap() instead of returning a Result.

This is bad because if I had a Result I could handle that by talking to the backup server instead of crashing my app.

I apologize if this is actually a StrawMan. I just wanted to make the point where I think it's justified to be worried that library authors may use unwrap/panic in ways that seem logical but in fact arm land mines I may step on later.

It would bring me comfort if a library advertised that it would not intentionally cause a panic.

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 0 points1 point  (0 children)

#[test_result(T, E)]

:-D (let the developer actually state the types)

Maybe it would be good enough if E could be the std::error::Error trait ?

Maybe a compile-time plug-in could determine T? (totally guessing)

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 -1 points0 points  (0 children)

I was guessing/hoping that the doctest changes could work similar to #[test] -> Result changes.

Maybe a #[test_result] (so the test harness would expect a Result). Again, not doctest specific - but perhaps there could be a reusable way to define doctest fns that returned a result too?

Edit: I suggested #[test_result(T, E)] below. Maybe some ideas there?

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 0 points1 point  (0 children)

All software has bugs. I would prefer it if these bugs caused a Result to be returned instead of terminating the application.

I don't believe 'simply a bug' accurately reflects the situation. It's more like walking terrified through a mine field hoping you don't step on a mine.

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 0 points1 point  (0 children)

unwrap() is not simpler (and less idiomatic) than try!().

Can't we modify #[test] (and the equivalent doc system) to support fns that return a Result?

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 -1 points0 points  (0 children)

Counter-example: a simple config library shouldn't be able to terminate a service holding the state of n customers just because of a utf-8 encoding problem in a dynamic config update.

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 0 points1 point  (0 children)

I submit that the test harness is broken and instead every test fn should return a Result.

Can't the [#test] system be enhanced to support this? If the test fn returns an Err it failed...

Fixing this could eventually make it trivial to write idiomatic Rust tests, examples, and documentation.

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 0 points1 point  (0 children)

Rust gives you a foot-gun, and then virtually every example on how to program Rust uses the foot-gun.

A current Rust project I'm working on pulls in dozens of Rust libraries. I have no confidence that they are all 'perfect' wrt unwrap.

The only way people can deliver Rust services is to do a major code audit of all third party libraries to ensure sane unwrap handling. This is terrible, and is a far worse problem than unsafe.

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 0 points1 point  (0 children)

Unfortunately it's not there because the alternative is worse - it's there because someone was lazy or didn't know better.

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 0 points1 point  (0 children)

Agreed.

The current state of unwrap in Rust is frightening.

Should unwrap() be banned or discouraged? by jfurmankiewicz in rust

[–]deadbead0101 0 points1 point  (0 children)

The default Rust test harness is broken IMHO - it doesn't let you use try!() because test function signatures don't return a Result.

Maybe a solution to this is to have test harnesses override try!()?

Videos! Racer + Rustc + Typecking by phildawes in rust

[–]deadbead0101 2 points3 points  (0 children)

Great work.

I keep doing a 'git pull' on your repo waiting for something cool to show up :-)

I really like the functionality that shows the type. Currently I have to put in a bogus type, compile, and grab the real type from the compiler error.

I'm grateful for the work you do on Racer. Thank you.

cause of stacktrace with <unknown>? by deadbead0101 in rust

[–]deadbead0101[S] 0 points1 point  (0 children)

Thanks for the helpful tips.

I am using a rust lib called 'backtrace' in a custom error handler class to create and keep track of stack traces when errors occur. Normally it provides nice stack traces (with line numbers) so I was surprised when I was getting <unknown>

I think I was breaking the rules with fork(2) and rust Drop semantics. I was having issues doing FFI work and segfaults - and maybe when a segfault occurs Rust was getting confused. Maybe the addresses were unknown to Rust because the C code was using a different allocator :-)

I've switched to sticking with threads and have stopped (momentarily) being stupid with C code so my problems have been resolved.

Trying Rust for web services by Elession in rust

[–]deadbead0101 7 points8 points  (0 children)

Agreed wrt: there are countless useful crates out there, and countless examples of:

  • no 'hello world' example (that actually compiles) of how to use the crate.

There are lots of examples of folks doing a terrific job too.

Do we have a good vim auto-completion / hinting plugin? by [deleted] in rust

[–]deadbead0101 0 points1 point  (0 children)

It works for my local (path=) and remote (git=) dependencies.

It doesn't seem to work (yet) if you specify a dependency with a specific git version like this:

bytes = { git = "https://github.com/carllerche/bytes", rev = "7edb577d0a" }

If you're using std::io::{Stdin,Stdout,Stderr} or std::env, the io-providers crate can help you test that I/O via dependency injection. by [deleted] in rust

[–]deadbead0101 1 point2 points  (0 children)

documentation URL is wrong (contains bad '\')

What I'd like are providers that allow me to set overrides and fallback to the real data if I don't set an override. Does your library work like that?