The standard library version of an `RwLock` may get poisoned if a thread
panics that holds a write lock. The `RwLock` from parking_lot [1] does
not get poisoned it instead released the lock on a panic. This allows us
to simplify the `ProgressOutput` API since it no longer returns any
errors. No more panics can occur on `ProgressOutput::drop()`. The
`Error` enum can thus be simplified as well because there is no need to
convert `PoisonErrors` anymore.
[1] https://github.com/Amanieu/parking_lot
This will fix the broken spinners that indicate steps which are
currently in progress. To achieve this the behavior of the progressbar
helper had to be adjusted.
The multibar does not work while a child process is run with
`std::process::Command`. Using multiple spinners without a multibar is
problematic as well because emitting warnings, infos and errors while a
single spinner is active will duplicate the spinners message. The
spinner will also absorb the last warning/error/info. Instead of
publishing warnings, errors and infos immediately they will now be
cached and only output when the current spinner finishes.
To make sure we can output all warnings to the user ProgressBars are no
longer exposed to the caller. Instead the active spinner will be
finished implicitly when a new spinner is allocated with the `message()`
function. Instead of relying on the `done()` function to be called the
progressbar now implements the `Drop` trait which will finish the last
spinner automatically.
Unfortunately, this introduces members that have to be mutable. To not
have to deal with mutable ProgressOutput all over the place the members
were put inside an RwLock. This allows us to use ProgressOutput from
inside multiple threads to emit warnings and errors.
This does two big things:
- We add custom error messages and conversions from other error types
into our own error type. This means we can create or modify more
fine grained errors rather than using whatever `failure::Error` gives
us. The first one we have is a `Cli` error, whereby calls to things
like wasm-bindgen or npm failed.
- We also make it so that `PBAR.error()` is called only on exit. We grab
a reference to whatever error gets passed up the chain, have it
generate a message to be printed as an error to PBAR, close up PBAR
like normal, and then print our actual error message to stderr!
The main benefits of this is that as long as we return an error, PBAR
will print and close itself up and we don't need to call it every time
or forget that we would need to call it, and we put error details
specifically into our error!
Closes#12
This commit does quite a few things in order to get this to work:
1. We move all of the code dealing with knowing which command to run
into it's own function. This wrapper command allows us to always
close out PBAR before dumping error output. This fixes a problem
where stderr and stdout were borked and not printing out error
messages correctly.
2. We then refactor the code that has a panic to return early with that
error message.
3. If the command we ran errored, we print out with PBAR that there was
an error with the program we ran (not wasm-pack itself) then dump the
stderr from the command to the actual stderr
This means we can abort early on without continuing any of the other
parts of wasm-pack and let the user know what the error was rather than
just saying "There's an error"
This commit allows us to have a global progress bar to write data to
giving us the following benefits:
- Consistent ways to handle types of messages such as errors and
warnings
- Easy interface to add progress bars of various types
- Easy to maintain, add new types of bars, or more while encapsulating
the login in a single module