Skip to content

Commit

Permalink
Update error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDokuchaev committed Mar 17, 2024
1 parent c94cd66 commit 9f154f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Example of output for [fail.md](tests/test_md_files/fail.md)
```bash
File: tests/test_md_files/fail.md:3 • Link: https://github.com/AlexanderDokuchaev/FAILED • Error: 404: Not Found
File: tests/test_md_files/fail.md:4 • Link: https://not_exist_github.githubcom/ • Error: 500: Internal Server Error
File: tests/test_md_files/fail.md:8 • Link: /test/fail.md1 • Error: Path does not exists in repository
File: tests/test_md_files/fail.md:9 • Link: fail.md1 • Error: Path does not exists in repository
File: tests/test_md_files/fail.md:13 • Link: /tests/test_md_files/fail.md#fail • Error: Not found fragment
File: tests/test_md_files/fail.md:15 • Link: not_exist_dir • Error: Path does not exists in repository
File: tests/test_md_files/fail.md:8 • Link: /test/fail.md1 • Error: Path not found
File: tests/test_md_files/fail.md:9 • Link: fail.md1 • Error: Path not found
File: tests/test_md_files/fail.md:13 • Link: /tests/test_md_files/fail.md#fail • Error: Fragment not found
File: tests/test_md_files/fail.md:15 • Link: not_exist_dir • Error: Path not found
❌ Found 6 dead links 🙀
```

Expand Down
21 changes: 13 additions & 8 deletions md_dead_link_check/link_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

TIMEOUT_RESPONSE_CODE = 408

MSG_TIMEOUT = "408: Timeout"
MSG_PATH_NOT_FOUND = "Path not found"
MSG_PATH_NOT_ADDED = "Path not added to repository"
MSG_FRAGMENT_NOT_FOUND = "Fragment not found"


@dataclass
class StatusInfo:
Expand Down Expand Up @@ -65,8 +70,8 @@ async def process_link(link: str, session: ClientSession, config: Config) -> Lin
return LinkStatus(link, str(e))
except asyncio.TimeoutError:
if TIMEOUT_RESPONSE_CODE in config.catch_response_codes:
return LinkStatus(link, err_msg="408: Timeout")
return LinkStatus(link, warn_msg="408: Timeout")
return LinkStatus(link, err_msg=MSG_TIMEOUT)
return LinkStatus(link, warn_msg=MSG_TIMEOUT)

return LinkStatus(link)

Expand Down Expand Up @@ -121,7 +126,7 @@ def check_path_links(

if not split_result.path:
if fragment not in md_file_info.fragments:
ret.append(StatusInfo(md_link, "Not found header"))
ret.append(StatusInfo(md_link, MSG_FRAGMENT_NOT_FOUND))
continue
else:
try:
Expand All @@ -133,25 +138,25 @@ def check_path_links(
abs_path = (md_abs_path.parent / split_result.path).resolve()
rel_path = abs_path.relative_to(root_dir)
except ValueError:
ret.append(StatusInfo(md_link, "Path is not within git repository"))
ret.append(StatusInfo(md_link, MSG_PATH_NOT_FOUND))
continue

if abs_path.as_posix() != abs_path.resolve().as_posix():
ret.append(StatusInfo(md_link, "Path is not within git repository"))
ret.append(StatusInfo(md_link, MSG_PATH_NOT_FOUND))
continue

if rel_path.as_posix() in md_data:
# Markdowns in repository
if fragment and fragment not in md_data[rel_path.as_posix()].fragments:
ret.append(StatusInfo(md_link, "Not found fragment"))
ret.append(StatusInfo(md_link, MSG_FRAGMENT_NOT_FOUND))
continue
else:
# Not markdown file
if not any(f.as_posix().startswith(rel_path.as_posix()) for f in files_in_repo):
if rel_path.exists():
ret.append(StatusInfo(md_link, "File does not added to repository"))
ret.append(StatusInfo(md_link, MSG_PATH_NOT_ADDED))
else:
ret.append(StatusInfo(md_link, "Path does not exists in repository"))
ret.append(StatusInfo(md_link, MSG_PATH_NOT_FOUND))
continue

ret.append(StatusInfo(md_link))
Expand Down
12 changes: 6 additions & 6 deletions tests/test_link_cheker.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ def test_fails():
),
StatusInfo(
link_info=LinkInfo(link="/test/fail.md1", location=Path("tests/test_md_files/fail.md"), line_num=8),
err_msg="Path does not exists in repository",
err_msg="Path not found",
),
StatusInfo(
link_info=LinkInfo(link="fail.md1", location=Path("tests/test_md_files/fail.md"), line_num=9),
err_msg="Path does not exists in repository",
err_msg="Path not found",
),
StatusInfo(
link_info=LinkInfo(
link="/tests/test_md_files/fail.md#fail",
location=Path("tests/test_md_files/fail.md"),
line_num=13,
),
err_msg="Not found fragment",
err_msg="Fragment not found",
warn_msg=None,
),
StatusInfo(
Expand All @@ -77,7 +77,7 @@ def test_fails():
location=Path("tests/test_md_files/fail.md"),
line_num=15,
),
err_msg="Path does not exists in repository",
err_msg="Path not found",
warn_msg=None,
),
]
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_exclude_links(exclude_links):
location=Path("tests/test_md_files/fail.md"),
line_num=13,
),
err_msg="Not found fragment",
err_msg="Fragment not found",
warn_msg=None,
),
StatusInfo(
Expand All @@ -137,7 +137,7 @@ def test_exclude_links(exclude_links):
location=Path("tests/test_md_files/fail.md"),
line_num=15,
),
err_msg="Path does not exists in repository",
err_msg="Path not found",
warn_msg=None,
),
]
Expand Down

0 comments on commit 9f154f7

Please sign in to comment.