In Toast we do some
Command usage that calls out to node and requires features only available in node v14. To check the available node version and provide a useful error message we use the following code to parse
node -v and check the version using the Rust
The error that shows when everything works is
we get similar output if other things go wrong as well.
We build a
Version struct manually that in this case points to
We set up a
Command that runs
node -v and try to capture the output. This could fail so we use eyre's tools to wrap the error with additional context if it does.
Command output brings
stdout in as a
Vec[u8] but we want a string so we run
from_utf8 on it, which could fail.
The trimmed version string is because Rust's
semver package doesn't handle
v in the semver string like node.js does, so we need to remove it. The
Version::parse handles whitespace trimming for us though.
Finally with all of the information we have we can do a comparison of the current node version against the minimum we support and relay relevant error messages regardless.