Hello to all of the people of this amazing language
First of all sorry for my english
I have a program in Rust, that is downloading a chapter of a comic in a webpage
I have doint first in the sync way, after that in async way and now i will try to learn more concepts about the errors and panic in rust.
In the last week, i have a problem, that many times when i download the chapter, some images are less than 195 bytes
Ok, no problem i have done a check, after i downloaded the image and write it, check the size of the file and if is ok, continue iterating throuth the links of the images, and if the size is less, delete the directory and panic.
This works 100% of the time, but because the web is very slow, many times i see something like this:
Fichero muy pequeño menor o igual 195 bytes, borrar directorio
Se ha borrado el directorio
thread 'main' panicked at 'explicit panic', src/main.rs:43:5
note: run with
RUST_BACKTRACE=1 environment variable to display a backtrace
It's okey rust have delete the directory and have done a panic! to exit the program..
But this got me thinking that is a better way of impleting this, i will try to explain,
I will transform my function to get an image to -> Result<(), Error>
This way i can raise and error, to get it, and delete the directory without panic (if this goes well)
i'm trying something like this:
But i have one problem i want to be easy.
i see that i have to iterate through the images and with .collect use to see the case of and image less that 195bytes (and in the first image corrupted this will stop) i have to delete the directory
but my problem is that rust is telling my that Error
cannot find value
fichero_pequeño in this scope
328 | Err(fichero_pequeño)
| ^^^^^^^^^^^^^^^ not found in this scope
i have to create an especific error to raise it, and checked in the superior function or i can have another way of solve it?
Many thanks to all