Repository: robocorp/rpaframework

Issue:
`RPA.Robocorp.Vault` - Meaningful error message when Vault isn't linked
The well known missing env var error message (raised [here](https://github.com/robocorp/rpaframework/blob/master/packages/main/src/RPA/Robocorp/Vault.py#L214)): `KeyError: 'Missing required environment variable: RC_API_SECRET_HOST'` proved to be cryptic among our users and they don't know what to do about it.
Just a few of them are searching our Forum/Docs/Slack against it and on how to link and work with the online or local Vault.

Proposal: Appending to the error message a URL too on how to link the Vault (`https://robocorp.com/docs/development-guide/variables-and-secrets/vault`) so they know what to do next instead of asking for help without searching first about the issue.

Any thoughts on this @mikahanninen ?


Discussion:

Resolving patch:
diff --git a/packages/main/src/RPA/Robocorp/Vault.py b/packages/main/src/RPA/Robocorp/Vault.py
--- a/packages/main/src/RPA/Robocorp/Vault.py
+++ b/packages/main/src/RPA/Robocorp/Vault.py
@@ -192,6 +192,38 @@ def set_secret(self, secret: Secret) -> None:
         self.save()
 
 
+def _raise_invalid_configuration():
+    missing_env_vars = [
+        var
+        for var in ["RC_API_SECRET_HOST", "RC_API_SECRET_TOKEN", "RC_WORKSPACE_ID"]
+        if not os.getenv(var)
+    ]
+    if missing_env_vars:  # Only proceed if there are missing variables.
+        missing_vars_str = ", ".join(missing_env_vars)
+
+        error_message = (
+            "Configuration Error: Missing required environment variable(s):"
+            f" {missing_vars_str}.\n\n"
+            "To connect to the Robocorp Control Room, these variables are essential. "
+            "Please verify your configuration to ensure that all required environment"
+            " variables are set.\n\n"
+            "For local runs, configure these variables in your 'devdata/env.json'"
+            " file.\n\n"
+            "Consult the 'Configure file vault support' section in the documentation"
+            " for step-by-step setup instructions:\n"
+            "https://robocorp.com/docs/development-guide/"
+            "variables-and-secrets/vault\n\n"
+            "When running from the Control Room, these variables should be "
+            "configured automatically.\n"
+            "If running with Robocorp Visual Studio Code extension, ensure that"
+            " the project is linked to Control Room:\n"
+            "https://robocorp.com/docs/developer-tools/visual-studio-code/"
+            "extension-features#linking-to-control-room"
+        )
+
+        raise KeyError(error_message)
+
+
 class RobocorpVault(BaseSecretManager):
     """Adapter for secrets stored in Robocorp Vault.
 
@@ -211,9 +243,12 @@ def __init__(self, *args, **kwargs):
         # pylint: disable=unused-argument
         self.logger = logging.getLogger(__name__)
         # Environment variables set by runner
-        self._host = required_env("RC_API_SECRET_HOST")
-        self._token = required_env("RC_API_SECRET_TOKEN")
-        self._workspace = required_env("RC_WORKSPACE_ID")
+        try:
+            self._host = required_env("RC_API_SECRET_HOST")
+            self._token = required_env("RC_API_SECRET_TOKEN")
+            self._workspace = required_env("RC_WORKSPACE_ID")
+        except KeyError:
+            _raise_invalid_configuration()
         # Generated lazily on request
         self.__private_key = None
         self.__public_bytes = None


Test patch: