Repository: conda-forge/conda-smithy

Issue:
Unexpected top-level keys in conda-forge.yml fail to display anything
### Solution to issue cannot be found in the documentation.

- [X] I checked the documentation.

### Issue

If a `conda-forge.yml` contains an unexpected top-level key, no useful output should be shown.

For example, given [this file](https://github.com/conda-forge/nbgrader-feedstock/blob/429a9cffba3dcccd99f8d4871452e4e5bce32e33/conda-forge.yml#L6), the error should probably be:

```
Additional properties are not allowed ('linux_ppc64le' was unexpected)
```

But instead seeing:

```
Traceback (most recent call last):
  File "~/env/bin/conda-smithy", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "~/env/lib/python3.11/site-packages/conda_smithy/cli.py", line 737, in main
    args.subcommand_func(args)
  File "~/env/lib/python3.11/site-packages/conda_smithy/cli.py", line 616, in __call__
    lints, hints = lint_recipe.main(
                   ^^^^^^^^^^^^^^^^^
  File "~/env/lib/python3.11/site-packages/conda_smithy/lint_recipe.py", line 1115, in main
    results.extend([_format_validation_msg(err) for err in validation_errors])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/env/lib/python3.11/site-packages/conda_smithy/lint_recipe.py", line 1115, in <listcomp>
    results.extend([_format_validation_msg(err) for err in validation_errors])
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/env/lib/python3.11/site-packages/conda_smithy/lint_recipe.py", line 1081, in _format_validation_msg
    error.json_path.split(".")[1].split("[")[0].replace("_", "-")

```

PR incoming.

### Installed packages

```shell
conda-smithy 3.34.0
```


### Environment info

```shell
CI
```



Discussion:

Resolving patch:
diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py
--- a/conda_smithy/lint_recipe.py
+++ b/conda_smithy/lint_recipe.py
@@ -1069,17 +1069,26 @@ def jinja_lines(lines):
 
 
 def _format_validation_msg(error: "jsonschema.ValidationError"):
+    """Use the data on the validation error to generate improved reporting.
+
+    If available, get the help URL from the first level of the JSON path:
+
+        $(.top_level_key.2nd_level_key)
+    """
+    help_url = "https://conda-forge.org/docs/maintainer/conda_forge_yml"
+    path = error.json_path.split(".")
+    descriptionless_schema = {}
+    subschema_text = ""
+
     if error.schema:
         descriptionless_schema = {
             k: v for (k, v) in error.schema.items() if k != "description"
         }
-    else:
-        descriptionless_schema = {}
-    # We can get the help url from the first level on the JSON path ($.top_level_key.2nd_level_key)
-    top_level_key = (
-        error.json_path.split(".")[1].split("[")[0].replace("_", "-")
-    )
-    help_url = f"https://conda-forge.org/docs/maintainer/conda_forge_yml/#{top_level_key}"
+
+    if len(path) > 1:
+        help_url += f"""/#{path[1].split("[")[0].replace("_", "-")}"""
+        subschema_text = json.dumps(descriptionless_schema, indent=2)
+
     return cleandoc(
         f"""
         In conda-forge.yml: [`{error.json_path}`]({help_url}) `=` `{error.instance}`.
@@ -1088,7 +1097,7 @@ def _format_validation_msg(error: "jsonschema.ValidationError"):
             <summary>Schema</summary>
 
             ```json
-{indent(json.dumps(descriptionless_schema, indent=2), " " * 12)}
+{indent(subschema_text, " " * 12)}
             ```
 
             </details>


Test patch: