Skip to content

Commit 9f154f7

Browse files
Update error messages
1 parent c94cd66 commit 9f154f7

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Example of output for [fail.md](tests/test_md_files/fail.md)
1919
```bash
2020
File: tests/test_md_files/fail.md:3 • Link: https://github.com/AlexanderDokuchaev/FAILED • Error: 404: Not Found
2121
File: tests/test_md_files/fail.md:4 • Link: https://not_exist_github.githubcom/ • Error: 500: Internal Server Error
22-
File: tests/test_md_files/fail.md:8 • Link: /test/fail.md1 • Error: Path does not exists in repository
23-
File: tests/test_md_files/fail.md:9 • Link: fail.md1 • Error: Path does not exists in repository
24-
File: tests/test_md_files/fail.md:13 • Link: /tests/test_md_files/fail.md#fail • Error: Not found fragment
25-
File: tests/test_md_files/fail.md:15 • Link: not_exist_dir • Error: Path does not exists in repository
22+
File: tests/test_md_files/fail.md:8 • Link: /test/fail.md1 • Error: Path not found
23+
File: tests/test_md_files/fail.md:9 • Link: fail.md1 • Error: Path not found
24+
File: tests/test_md_files/fail.md:13 • Link: /tests/test_md_files/fail.md#fail • Error: Fragment not found
25+
File: tests/test_md_files/fail.md:15 • Link: not_exist_dir • Error: Path not found
2626
❌ Found 6 dead links 🙀
2727
```
2828

md_dead_link_check/link_checker.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
TIMEOUT_RESPONSE_CODE = 408
1919

20+
MSG_TIMEOUT = "408: Timeout"
21+
MSG_PATH_NOT_FOUND = "Path not found"
22+
MSG_PATH_NOT_ADDED = "Path not added to repository"
23+
MSG_FRAGMENT_NOT_FOUND = "Fragment not found"
24+
2025

2126
@dataclass
2227
class StatusInfo:
@@ -65,8 +70,8 @@ async def process_link(link: str, session: ClientSession, config: Config) -> Lin
6570
return LinkStatus(link, str(e))
6671
except asyncio.TimeoutError:
6772
if TIMEOUT_RESPONSE_CODE in config.catch_response_codes:
68-
return LinkStatus(link, err_msg="408: Timeout")
69-
return LinkStatus(link, warn_msg="408: Timeout")
73+
return LinkStatus(link, err_msg=MSG_TIMEOUT)
74+
return LinkStatus(link, warn_msg=MSG_TIMEOUT)
7075

7176
return LinkStatus(link)
7277

@@ -121,7 +126,7 @@ def check_path_links(
121126

122127
if not split_result.path:
123128
if fragment not in md_file_info.fragments:
124-
ret.append(StatusInfo(md_link, "Not found header"))
129+
ret.append(StatusInfo(md_link, MSG_FRAGMENT_NOT_FOUND))
125130
continue
126131
else:
127132
try:
@@ -133,25 +138,25 @@ def check_path_links(
133138
abs_path = (md_abs_path.parent / split_result.path).resolve()
134139
rel_path = abs_path.relative_to(root_dir)
135140
except ValueError:
136-
ret.append(StatusInfo(md_link, "Path is not within git repository"))
141+
ret.append(StatusInfo(md_link, MSG_PATH_NOT_FOUND))
137142
continue
138143

139144
if abs_path.as_posix() != abs_path.resolve().as_posix():
140-
ret.append(StatusInfo(md_link, "Path is not within git repository"))
145+
ret.append(StatusInfo(md_link, MSG_PATH_NOT_FOUND))
141146
continue
142147

143148
if rel_path.as_posix() in md_data:
144149
# Markdowns in repository
145150
if fragment and fragment not in md_data[rel_path.as_posix()].fragments:
146-
ret.append(StatusInfo(md_link, "Not found fragment"))
151+
ret.append(StatusInfo(md_link, MSG_FRAGMENT_NOT_FOUND))
147152
continue
148153
else:
149154
# Not markdown file
150155
if not any(f.as_posix().startswith(rel_path.as_posix()) for f in files_in_repo):
151156
if rel_path.exists():
152-
ret.append(StatusInfo(md_link, "File does not added to repository"))
157+
ret.append(StatusInfo(md_link, MSG_PATH_NOT_ADDED))
153158
else:
154-
ret.append(StatusInfo(md_link, "Path does not exists in repository"))
159+
ret.append(StatusInfo(md_link, MSG_PATH_NOT_FOUND))
155160
continue
156161

157162
ret.append(StatusInfo(md_link))

tests/test_link_cheker.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ def test_fails():
5656
),
5757
StatusInfo(
5858
link_info=LinkInfo(link="/test/fail.md1", location=Path("tests/test_md_files/fail.md"), line_num=8),
59-
err_msg="Path does not exists in repository",
59+
err_msg="Path not found",
6060
),
6161
StatusInfo(
6262
link_info=LinkInfo(link="fail.md1", location=Path("tests/test_md_files/fail.md"), line_num=9),
63-
err_msg="Path does not exists in repository",
63+
err_msg="Path not found",
6464
),
6565
StatusInfo(
6666
link_info=LinkInfo(
6767
link="/tests/test_md_files/fail.md#fail",
6868
location=Path("tests/test_md_files/fail.md"),
6969
line_num=13,
7070
),
71-
err_msg="Not found fragment",
71+
err_msg="Fragment not found",
7272
warn_msg=None,
7373
),
7474
StatusInfo(
@@ -77,7 +77,7 @@ def test_fails():
7777
location=Path("tests/test_md_files/fail.md"),
7878
line_num=15,
7979
),
80-
err_msg="Path does not exists in repository",
80+
err_msg="Path not found",
8181
warn_msg=None,
8282
),
8383
]
@@ -128,7 +128,7 @@ def test_exclude_links(exclude_links):
128128
location=Path("tests/test_md_files/fail.md"),
129129
line_num=13,
130130
),
131-
err_msg="Not found fragment",
131+
err_msg="Fragment not found",
132132
warn_msg=None,
133133
),
134134
StatusInfo(
@@ -137,7 +137,7 @@ def test_exclude_links(exclude_links):
137137
location=Path("tests/test_md_files/fail.md"),
138138
line_num=15,
139139
),
140-
err_msg="Path does not exists in repository",
140+
err_msg="Path not found",
141141
warn_msg=None,
142142
),
143143
]

0 commit comments

Comments
 (0)