[ffx] Fix strict handling of env vars in config

When in strict mode, we need to reject env vars. But rather than
just not doing the env_var mapping, which would leave the strings
as "$ENV_VAR" which is never what we want. It would cause problems
like failing to find separately-built tools, or failing to find
the SDK path, without providing a useful error message.

Instead, we should actionable error to the user, reporting the
name of the config variable that failed, and show them the string
that failed to be map.

This requires some surgery to config: e.g. getting away from the type
magic involved in TryFrom (and its associated error type). Instead,
there is now a TryConvert trait which always returns ConfigError.
There is also a new member of the ConfigError enum, BadValue, which
is only returned (currently) when in strict mode. It contains a useful
description of why the conversion failed.

This error was introduced because it can carry information about why
the failure occurred, but it also lets a caller determine whether they
care whether it failed. In some cases (e.g. in get_target_specifier())
we can just ignore it and assume the value is None. There is now a
convenience function, get_optional(), which the caller can use when
it doesn't care about this particular error.

Fixed: 383636241
Fixed: 382333204
Change-Id: Ica197d41f92d44d96b40c898795b4b7d20bcb758
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1177196
Commit-Queue: Steven Grady <slgrady@google.com>
Reviewed-by: Colin Nelson <colnnelson@google.com>
11 files changed
tree: 90db8866b3b4cda68b18ebf5680565cf61f3e68b
  1. boards/
  2. build/
  3. bundles/
  4. docs/
  5. examples/
  6. infra/
  7. products/
  8. scripts/
  9. sdk/
  10. src/
  11. third_party/
  12. tools/
  13. zircon/
  14. .clang-format
  15. .clang-tidy
  16. .editorconfig
  17. .git-blame-ignore-revs
  18. .gitattributes
  19. .gitignore
  20. .gitmodules
  21. .gn
  22. .ignore
  23. analysis_options.yaml
  24. AUTHORS
  25. BUILD.gn
  26. CODE_OF_CONDUCT.md
  27. CONTRIBUTING.md
  28. fuchsia.code-workspace
  29. LICENSE
  30. OWNERS
  31. PATENTS
  32. pyproject.toml
  33. pyrightconfig.json
  34. README.md
  35. rustfmt.toml
  36. shac.star
  37. shac.textproto
README.md

Fuchsia

What is Fuchsia?

Fuchsia is an open source, general purpose operating system supporting modern 64-bit Intel and ARM processors.

We expect everyone interacting with our project to respect our code of conduct.

Read more about Fuchsia's principles.

How can I build and run Fuchsia?

See Getting Started.

Where can I learn more about Fuchsia?

See fuchsia.dev.