@@ -61,8 +61,7 @@ def read_metadata_schema(filepath: str) -> Dict[str, Any]:
6161 Dict[str, Any]: The JSON schema as a dictionary.
6262 """
6363 if not os .path .exists (filepath ):
64- logger .info (f"Error: File '{ filepath } ' does not exist." )
65- return {}
64+ raise FileNotFoundError (f"Error: File '{ filepath } ' does not exist." )
6665
6766 try :
6867 with open (filepath , encoding = "utf-8" ) as file :
@@ -78,8 +77,8 @@ def read_metadata_schema(filepath: str) -> Dict[str, Any]:
7877
7978 # Additional debugging info: Check expected keys
8079 if "$schema" not in schema or "type" not in schema :
81- logger .info (
82- "Warning: Schema may be missing key fields like '$schema' or 'type'."
80+ logger .warning (
81+ "Schema may be missing key fields like '$schema' or 'type'."
8382 )
8483
8584 logger .info (
@@ -89,11 +88,9 @@ def read_metadata_schema(filepath: str) -> Dict[str, Any]:
8988 return schema
9089
9190 except json .JSONDecodeError as e :
92- logger .info (f"Error reading JSON: { e } " )
93- return {}
91+ raise Exception (f"Error reading JSON: { e } " )
9492 except Exception as e :
95- logger .info (f"An unexpected error occurred while reading the schema: { e } " )
96- return {}
93+ raise Exception (f"An unexpected error occurred while reading the schema: { e } " )
9794
9895
9996# def generate_example_old(
@@ -220,7 +217,8 @@ def save_json(data: Dict[str, Any], filename: Path) -> None:
220217 filename (str): The filename where the JSON data will be saved.
221218 """
222219 with open (filename , "w" , encoding = "utf-8" ) as file :
223- json .dump (data , file , ensure_ascii = False , indent = 4 )
220+ json .dump (data , file , indent = 2 )
221+ file .write ("\n " )
224222
225223 logger .info (f"example JSON generated and saved to { filename } " )
226224
@@ -262,7 +260,8 @@ def replace_key_in_json(file_path, target_key, new_value):
262260 if find_and_replace_key (data , target_key , new_value ):
263261 # Save the updated JSON data back to the file
264262 with open (file_path , "w" , encoding = "utf-8" ) as file :
265- json .dump (data , file , ensure_ascii = False , indent = 4 )
263+ json .dump (data , file , ensure_ascii = False , indent = 2 )
264+ file .write ("\n " )
266265 logger .info (f"Updated '{ target_key } ' to '{ new_value } ' in { file_path } " )
267266 else :
268267 logger .info (f"Key '{ target_key } ' not found in JSON file." )
0 commit comments