Skip to content

Commit 721ccd7

Browse files
committed
Improve the log when a single file fails
1 parent 98e294e commit 721ccd7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

html2notion/main.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ async def import_single_file(file):
7070
async with ClientSession() as session:
7171
async with AsyncClient(auth=notion_api_key) as notion_client:
7272
notion_importer = NotionImporter(session, notion_client)
73-
result = await notion_importer.process_file(file)
74-
return result
75-
73+
try:
74+
result = await notion_importer.process_file(file)
75+
logger.info(f"Finish file {file}")
76+
return ("succ", result)
77+
except Exception as e:
78+
logger.error(f"Error processing {file}: {str(e)}")
79+
return ("fail", str(e))
7680

7781
def main():
7882
args = parse_args()
@@ -82,12 +86,14 @@ def main():
8286
dir_path = Path(args.dir) if args.dir else None
8387
max_concurrency = args.batch
8488
if file_path and file_path.is_file():
85-
logger.debug(f"Begin save single html file: {file_path}.")
8689
result = asyncio.run(import_single_file(file_path))
87-
logger.debug(f"Finish save single html file: {file_path}.\n{result}")
8890
text = Text("Single file ", style="default")
8991
text.append(f"{file_path} ", style="cyan")
90-
text.append("save to notion success.", style="default")
92+
if result[0] == "fail":
93+
text.append("save to notion failed.", style="default")
94+
text.append(f"\n{result[1]}", style="red")
95+
else:
96+
text.append("save to notion success.", style="default")
9197
console.print(text)
9298
elif dir_path and dir_path.is_dir():
9399
logger.info(f"Begin save all html files in the dir: {dir_path}.")

html2notion/translate/notion_import.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ async def create_new_page(self, notion_data):
4444
# logger.debug(f'Create new page: {notion_data["parent"]}, {notion_data["properties"]}')
4545
# body.children.length should be ≤ `100`,
4646
blocks = notion_data.get("children", [])
47+
# logger.debug(f'Create new page: {notion_data["parent"]}, {notion_data["properties"]}, blocks: {blocks}')
48+
4749
limit_size = 100
4850
chunks = [blocks[i: i + limit_size] for i in range(0, len(blocks), limit_size)]
4951
if blocks:

0 commit comments

Comments
 (0)