Skip to content
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

What are we doing here in Curl.rs #39

Closed
KMastroluca opened this issue Oct 2, 2023 · 2 comments
Closed

What are we doing here in Curl.rs #39

KMastroluca opened this issue Oct 2, 2023 · 2 comments

Comments

@KMastroluca
Copy link
Contributor

im confused by this.

            transfer

                .write_function(|new_data| {
                    let mut data = data.borrow_mut();
                    data.extend_from_slice(new_data);
                    Ok(new_data.len())
                })
                .unwrap();

Why are we unwrapping here, when the value isnt being assigned to anything?
im currently debugging an issue I ran into related to trying to submit nonsense requests. We crashed because later in this function call we try to unwrap an error when we were expecting a value. I fixed that

            match transfer.perform() {
                Ok(_) => {
                    let res = String::from_utf8(data.take()).unwrap();
                    self.resp = Some(res.clone());
                    Ok(())

                }
                Err(e) => {
                    let res = format!("Error Executing Curl Request: {}", e);
                    self.resp = Some(res.clone());
                    Err(e)
                }
            }

Now we match on the transfer.perform() and anything that results from it, success or error, will get thrown into self.resp so we can display the result to the user.

This does avoid the panic I encountered with a nonsense request
but im not seeing the error / response displayed, just a blank screen, so im pretty confused. Im looking into it further and I encountered that .unwrap() without an assignment. Whats that for?

@KMastroluca
Copy link
Contributor Author

I figured it out, im retarded sorry.

closed #39

@PThorpe92
Copy link
Owner

Lol ok cool. I was in the middle of explaining when you closed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants