Skip to content

Commit c2b7473

Browse files
authored
Check whether json2ts exited without any errors before processing the generated ts file (#14)
* When a generated ts file already exists but json2ts fails to write a new file due to whatever reason 'remove_master_model_from_output' is still called, this results in a confusing error message. Instead check exit code of json2ts and output it to log.
1 parent 65f8aae commit c2b7473

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pydantic2ts/cli/script.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,17 @@ def generate_typescript_defs(
210210

211211
logger.info("Converting JSON schema to typescript definitions...")
212212

213-
os.system(f'{json2ts_cmd} -i {schema_file_path} -o {output} --bannerComment ""')
214-
shutil.rmtree(schema_dir)
215-
remove_master_model_from_output(output)
213+
json2ts_exit_code = os.system(
214+
f'{json2ts_cmd} -i {schema_file_path} -o {output} --bannerComment ""'
215+
)
216216

217-
logger.info(f"Saved typescript definitions to {output}.")
217+
if json2ts_exit_code == 0:
218+
remove_master_model_from_output(output)
219+
logger.info(f"Saved typescript definitions to {output}.")
220+
else:
221+
logger.error(f"{json2ts_cmd} failed with exit code {json2ts_exit_code}.")
222+
223+
shutil.rmtree(schema_dir)
218224

219225

220226
def parse_cli_args(args: List[str] = None) -> argparse.Namespace:

0 commit comments

Comments
 (0)