From 478ac619756ce9e103218afb10a0ce2eb75f3124 Mon Sep 17 00:00:00 2001 From: Andrew Yim Date: Sat, 27 Jun 2026 10:08:20 +0900 Subject: [PATCH] fix(notion-writer): fail loudly on markdown image append + upsert prop update Mirror the blocks path's error handling in the markdown engine: - page + DB markdown two-phase image append now check append_to_page's return and exit(1) on failure instead of printing success silently - markdown DB upsert guards update_page_properties return - restore blocks-engine page progress print + replace-failure print - move unused parent computation into the create branch Co-Authored-By: Claude Opus 4.8 (1M context) --- .../code/scripts/notion_writer.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/custom-skills/32-notion-writer/code/scripts/notion_writer.py b/custom-skills/32-notion-writer/code/scripts/notion_writer.py index 267490d..f0a1dbd 100644 --- a/custom-skills/32-notion-writer/code/scripts/notion_writer.py +++ b/custom-skills/32-notion-writer/code/scripts/notion_writer.py @@ -976,8 +976,9 @@ Examples: except APIResponseError as exc: print(f"Error: {compat.explain_api_error(exc, formatted_id)}") sys.exit(1) - if local_imgs: - append_to_page(notion, page_id, _upload_blocks_for(local_imgs)) + if local_imgs and not append_to_page(notion, page_id, _upload_blocks_for(local_imgs)): + print("❌ Text was written but image append failed") + sys.exit(1) print("✅ Successfully wrote content to page (markdown engine)") print(f" https://notion.so/{formatted_id.replace('-', '')}") return @@ -990,7 +991,9 @@ Examples: if not blocks: print("No content to write") sys.exit(1) + print(f"{'Replacing' if args.replace else 'Appending'} content to page...") if args.replace and not clear_page_content(notion, page_id): + print("❌ Failed to write content") sys.exit(1) if append_to_page(notion, page_id, blocks): print("✅ Successfully wrote content to page") @@ -1080,22 +1083,24 @@ Examples: ntn_files.preflight() md_body, local_imgs = extract_local_images(md_content) md_body = md_translate.translate(md_body) - parent = compat.build_data_source_parent(data_source_id) mc = _md_client() try: if args.upsert_by and existing: compat.replace_markdown(mc, existing['id'], md_body, allow_deleting=args.allow_deleting) - update_page_properties(notion, existing['id'], properties) + if not update_page_properties(notion, existing['id'], properties): + sys.exit(1) new_id = existing['id'] else: + parent = compat.build_data_source_parent(data_source_id) result = compat.create_page_markdown(mc, parent, properties, md_body) new_id = result['id'] except APIResponseError as exc: print(f"Error: {compat.explain_api_error(exc)}") sys.exit(1) - if local_imgs: - append_to_page(notion, new_id, _upload_blocks_for(local_imgs)) + if local_imgs and not append_to_page(notion, new_id, _upload_blocks_for(local_imgs)): + print("❌ Text was written but image append failed") + sys.exit(1) print("✅ Successfully wrote database row (markdown engine)") print(f" https://notion.so/{new_id.replace('-', '')}") return