stac-validator 3.9.0__tar.gz → 3.9.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stac_validator
3
- Version: 3.9.0
3
+ Version: 3.9.2
4
4
  Summary: A package to validate STAC files
5
5
  Home-page: https://github.com/stac-utils/stac-validator
6
6
  Author: James Banting, Jonathan Healy
@@ -2,7 +2,7 @@
2
2
 
3
3
  from setuptools import setup
4
4
 
5
- __version__ = "3.9.0"
5
+ __version__ = "3.9.2"
6
6
 
7
7
  with open("README.md", "r") as fh:
8
8
  long_description = fh.read()
@@ -267,21 +267,39 @@ class StacValidate:
267
267
  schema_value = str(self.schema)
268
268
  schema_field: List[str] = [schema_value] if schema_value else []
269
269
 
270
+ # Initialize the message with common fields
270
271
  message: Dict[str, Union[str, bool, List[str], Dict[str, Any]]] = {
271
272
  "version": version_str,
272
273
  "path": path_str,
273
- "schema": schema_field, # Ensure schema is a list of strings or None
274
+ "schema": schema_field, # All schemas that were checked
274
275
  "valid_stac": False,
275
276
  "error_type": err_type,
276
277
  "error_message": err_msg,
278
+ "failed_schema": "", # Will be populated if we can determine which schema failed
277
279
  }
278
280
 
281
+ # Try to extract the failed schema from the error message if it's a validation error
282
+ if error_obj and hasattr(error_obj, "schema"):
283
+ if isinstance(error_obj.schema, dict) and "$id" in error_obj.schema:
284
+ message["failed_schema"] = error_obj.schema["$id"]
285
+ elif hasattr(error_obj, "schema_url"):
286
+ message["failed_schema"] = error_obj.schema_url
287
+ # If we can't find a schema ID, try to get it from the schema map
288
+ elif schema_field and len(schema_field) == 1:
289
+ message["failed_schema"] = schema_field[0]
290
+
279
291
  if self.verbose and error_obj is not None:
280
292
  verbose_err = self._create_verbose_err_msg(error_obj)
281
293
  if isinstance(verbose_err, dict):
282
294
  message["error_verbose"] = verbose_err
283
295
  else:
284
296
  message["error_verbose"] = {"detail": str(verbose_err)}
297
+ # Add recommendation to check the schema if the error is not clear
298
+ if "failed_schema" in message and message["failed_schema"]:
299
+ message["recommendation"] = (
300
+ "If the error is unclear, please check the schema documentation at: "
301
+ f"{message['failed_schema']}"
302
+ )
285
303
  else:
286
304
  message["recommendation"] = (
287
305
  "For more accurate error information, rerun with --verbose."
@@ -459,25 +477,39 @@ class StacValidate:
459
477
  if e.context:
460
478
  e = best_match(e.context) # type: ignore
461
479
  valid = False
462
- if e.absolute_path:
463
- err_msg = (
464
- f"{e.message}. Error is in "
465
- f"{' -> '.join(map(str, e.absolute_path))} "
466
- )
467
- else:
468
- err_msg = f"{e.message}"
480
+ # Get the current schema (extension) that caused the validation error
481
+ failed_schema = self._original_schema_paths.get(extension, extension)
482
+ # Build the error message with path information
483
+ path_info = (
484
+ f"Error is in {' -> '.join(map(str, e.absolute_path))} "
485
+ if e.absolute_path
486
+ else ""
487
+ )
488
+ err_msg = f"{e.message}. {path_info}"
489
+
490
+ # Create the error message with the original error object
469
491
  message = self.create_err_msg(
470
492
  err_type="JSONSchemaValidationError",
471
493
  err_msg=err_msg,
472
494
  error_obj=verbose_error,
473
495
  )
496
+
497
+ # Set the failed_schema in the message if we have it
498
+ if failed_schema:
499
+ message["failed_schema"] = failed_schema
474
500
  return message
475
501
 
476
502
  except Exception as e:
477
503
  if self.recursive:
478
504
  raise
479
505
  valid = False
480
- err_msg = f"{e}. Error in Extensions."
506
+ # Include the current schema in the error message for other types of exceptions
507
+ current_schema = (
508
+ self._original_schema_paths.get(extension, extension)
509
+ if "extension" in locals()
510
+ else "unknown schema"
511
+ )
512
+ err_msg = f"{e} [Schema: {current_schema}]. Error in Extensions."
481
513
  return self.create_err_msg(
482
514
  err_type="Exception", err_msg=err_msg, error_obj=e
483
515
  )
@@ -649,10 +681,22 @@ class StacValidate:
649
681
  Args:
650
682
  item_collection (dict): The dictionary representation of the item collection.
651
683
  """
684
+ # Store the original stac_file to restore it later
685
+ original_stac_file = self.stac_file
686
+
652
687
  for item in item_collection["features"]:
688
+ # Update the path to include the item ID for better traceability
689
+ if isinstance(original_stac_file, str) and "id" in item:
690
+ # Remove any query string from the URL before appending the item ID
691
+ base_url = original_stac_file.split("?")[0]
692
+ self.stac_file = f"{base_url}/{item['id']}"
693
+
653
694
  self.schema = ""
654
695
  self.validate_dict(item)
655
696
 
697
+ # Restore the original stac_file
698
+ self.stac_file = original_stac_file
699
+
656
700
  def validate_collections(self) -> None:
657
701
  """
658
702
  Validate STAC Collections from a /collections endpoint.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stac-validator
3
- Version: 3.9.0
3
+ Version: 3.9.2
4
4
  Summary: A package to validate STAC files
5
5
  Home-page: https://github.com/stac-utils/stac-validator
6
6
  Author: James Banting, Jonathan Healy
File without changes
File without changes
File without changes