Skip to content

fix: handle empty URL parts in edit_uri to prevent TypeError#149

Open
suraj-aleph wants to merge 1 commit intobackstage:masterfrom
suraj-aleph:fix/edit-uri-empty-parts-typeerror
Open

fix: handle empty URL parts in edit_uri to prevent TypeError#149
suraj-aleph wants to merge 1 commit intobackstage:masterfrom
suraj-aleph:fix/edit-uri-empty-parts-typeerror

Conversation

@suraj-aleph
Copy link
Copy Markdown

Summary

Fixes a TypeError crash in edit_uri.py when the monorepo plugin processes root-level pages (e.g. index.md).

Problem

__get_page_dir_alias splits page.url by / and pops parts in a while True loop until it finds a matching alias. For root-level pages the URL is empty or has no directory component, so parts becomes an empty list — and path.join(*parts) raises:

TypeError: join() missing 1 required positional argument: 'a'

Full traceback:

File "mkdocs_monorepo_plugin/edit_uri.py", line 37, in __get_page_dir_alias
    alias = path.join(*parts)
TypeError: join() missing 1 required positional argument: 'a'

This affects any project using the monorepo plugin with root-level pages in the main docs/ directory alongside !included sub-projects.

Fix

Two changes in edit_uri.py:

  1. __get_page_dir_alias: Replace the while True loop with while parts so it terminates safely. Use path.join(*parts) if parts else "" to handle the final iteration. Return None when no alias matches instead of looping into a crash.

  2. build: When __get_page_dir_alias() returns None (page doesn't belong to any included sub-project), fall back to the page's default edit_url instead of proceeding to methods that would KeyError on a None alias.

Related

Fixes #131

🤖 Generated with Claude Code

`__get_page_dir_alias` crashes with `TypeError: join() missing 1
required positional argument` when processing root-level pages
(e.g. `index.md`). The page URL splits into parts that become empty
after popping, and `path.join(*parts)` fails on an empty list.

Guard the loop to terminate when parts is exhausted, and return
None when no alias matches. In `build()`, fall back to the page's
default edit_url when no alias is found.

Fixes backstage#131

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can you make the monorepo plugin compatible with the mkdocs D2 plugin?

1 participant