-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rustify recent changes according to @plietar #111
Conversation
Somewhat uniform coding style might help myself to better understand Rust :-)
ok, also do you want to remove the |
Thanks, just need to check the new behaviour when trying to hook to a port thats <1024 for the zeroconf option, then will merge. |
The error when trying to bind to a priviledged port when run as non-root is:
this is a little too cryptic, we need to handle the error and panic with a proper message. |
src/main.rs
Outdated
|
||
let zeroconf_port = | ||
matches.opt_str("zeroconf-port") | ||
.map(|volume| volume.parse::<u16>().unwrap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct me if I'm wrong, but this shouldn't be volume should it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, it shouldn't. Probably a copypasta. Also, we need to handle the error when a non-root user tries to set a priviledged port (<1024). Currently it panics with a cryptic error, we need to display a proper error, or default to port 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be more inclined to say it should through an error (that a human can understand) and quit, as more that likely if you're changing this port its for a reason. However talking of panics like you said elsewhere I don't think a volume out of range is panic worthy, just set as default and show a debug message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to make a decision now with regards to how we approach problems like this in future. Do we want librespot to be user friendly, or require precision? If the latter, we should just fail hard on any bad input, or we accomodate bad inputs and throw warnings. Either way, we need to be consistent...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we're planning a daemon for the future that is going to be user friendly, it can be responsible for potentially fixing inputs. Librespot on its own should require precision as it is after all a library.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. So it should panic on initial-volume as paul suggested, and also on priviledged ports when not run as root.
I think I'd second the opinion that if we're going to have a daemon, then we can stay cryptic in librespot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going for the precision approach, initial-volume and zeroconf-port should both panic with bad values, the latter when trying to use a priviledged port as a non-root user.
There's no reason to catch ports under 1024 at this point in time.
|
All valid reasons for not defaulting to anything if one tries to set a port under 1024, but surely we should at least panic so that it doesn't just look like a bug? I note that it crashes here: https://github.com/librespot-org/librespot/blob/master/src/discovery.rs#L218, shouldn't we have a handler for the error that just panics with 'Unable to bind port' or similar? Currently there is nothing when it errors to point the user to their use of --zeroconf-port being the issue... |
I see no reason that it shouldn't panic and give an informative error at least then said user will hopefully not create an issue. |
Given that we're going for the panic on bad initial-volume and when ports are already taken/unusable, please add an error handler to Line 218 in 53fab4d
|
Haha... if only I knew how to do this. I guess that'll be the next Rust lesson for me. |
Would this just be a case of replacing unwrap() with expect("some informative error message")? |
Hmm... I applied @kingosticks' suggestion, pushed to my repository. But the change wouldn't show up here? |
I think I had the same issue and put it down to changing my origin to the new one. I think github gets confused. |
If it's easier, you could open a new PR |
Wow... this repository no longer shows up in the list of repositories I could use as a base fork to submit a pull request! Somehow my fork has lost any link to this repository... |
Maybe the reason is that librespot-org was "unforked" from the plietar repo by Github to enable searching. |
I'm closing this PR, as I had to fix my repository setup due to the "unforking". |
Somewhat uniform coding style might help myself to better understand Rust :-)