Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants