From fe566537f31963b46229de69e50fbb95de76666b Mon Sep 17 00:00:00 2001 From: Charles Stern <62192187+cisaacstern@users.noreply.github.com> Date: Tue, 21 Nov 2023 10:45:58 -0800 Subject: [PATCH] jsondecodeerror could happen with either file or inline --- action/deploy_recipe.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/action/deploy_recipe.py b/action/deploy_recipe.py index 8d367aa..0e91aca 100644 --- a/action/deploy_recipe.py +++ b/action/deploy_recipe.py @@ -55,24 +55,24 @@ def main(): # parse config print(f"pangeo-forge-runner-config provided as {config_string}") - if os.path.exists(config_string): - # we allow local paths pointing to json files - print(f"Loading json from file '{config_string}'...") - with open(config_string) as f: - config = json.load(f) - else: - # or json strings passed inline in the workflow yaml - print(f"{config_string} does not exist as a file. Loading json from string...") - try: + try: + if os.path.exists(config_string): + # we allow local paths pointing to json files + print(f"Loading json from file '{config_string}'...") + with open(config_string) as f: + config = json.load(f) + else: + # or json strings passed inline in the workflow yaml + print(f"{config_string} does not exist as a file. Loading json from string...") config = json.loads(config_string) - except json.JSONDecodeError as e: - raise ValueError( - f"{config_string} failed to parse to JSON. If you meant to pass a JSON string, " - "please confirm that it is correctly formatted. If you meant to pass a filename, " - "please confirm this path exists. Note, pangeo-forge/deploy-recipe-action should " - "always be invoked after actions/checkout, therefore the provided path must be " - "given relative to the repo root." - ) from e + except json.JSONDecodeError as e: + raise ValueError( + f"{config_string} failed to parse to JSON. If you meant to pass a JSON string, " + "please confirm that it is correctly formatted. If you meant to pass a filename, " + "please confirm this path exists. Note, pangeo-forge/deploy-recipe-action should " + "always be invoked after actions/checkout, therefore the provided path must be " + "given relative to the repo root." + ) from e # log variables to stdout print(f"{head_ref = }")