Skip to content

feat: improve InvalidIndexFile error to mention index file names#1859

Merged
mre merged 4 commits intolycheeverse:masterfrom
rina-forks:index-files-error
Sep 30, 2025
Merged

feat: improve InvalidIndexFile error to mention index file names#1859
mre merged 4 commits intolycheeverse:masterfrom
rina-forks:index-files-error

Conversation

@katrinafyi
Copy link
Member

this makes it clearer which files are causing the link check to fail. it also lets us customise the message in the special case of --index-files '', which could otherwise be confusing with a generic message.

the messages are:

[ERROR] file:///h | Cannot find index file within directory: An index file (index.html) is required
[ERROR] file:///h | Cannot find index file within directory: An index file (index.html, or index.htm) is required
[ERROR] file:///h | Cannot find index file within directory: An index file (index.html, index.htm, or index.md) is required

and for the --index-files '' case:

[ERROR] file:///h | Cannot find index file within directory: No directory links are allowed because index_files is defined and empty

i do wonder if this last error message is still confusing because of the "Cannot find index file within directory" text. maybe it should be changed to a more general "Cannot resolve link to local directory" or "Invalid local directory link"?

for comparison, the old message was this:

[ERROR] file:///h | Cannot find index file within directory: Index file not found in directory. Check if index.html or other index files exist

and it was constant and never changed.

this makes it clearer which files are causing the link check to fail.
it also lets us customise the message in the special case of
`--index-files ''`, which could otherwise be confusing with a generic
message.

the messages are:
```
[ERROR] file:///h | Cannot find index file within directory: An index file (index.html) is required
[ERROR] file:///h | Cannot find index file within directory: An index file (index.html, or index.htm) is required
[ERROR] file:///h | Cannot find index file within directory: An index file (index.html, index.htm, or index.md) is required
```

and for the `--index-files ''` case:
```
[ERROR] file:///h | Cannot find index file within directory: No directory links are allowed because index_files is defined and empty
```

i do wonder if this last error message is still confusing because of the
"Cannot find index file within directory" text. maybe it should be
changed to a more general "Cannot resolve link to local directory"?

for comparison, the old message was always:
```
[ERROR] file:///h | Cannot find index file within directory: Index file not found in directory. Check if index.html or other index files exist
```
ErrorKind::InvalidIndexFile(index_files) => match &index_files[..] {
[] => "No directory links are allowed because index_files is defined and empty".to_string(),
[name] => format!("An index file ({name}) is required"),
[init @ .., tail] => format!("An index file ({}, or {}) is required", init.join(", "), tail),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had no clue you could do init @ ..

@mre
Copy link
Member

mre commented Sep 30, 2025

Definitely much clearer. I don't really have a strong opinion on your --index-files '' case, but it does read fine to me.

@mre mre merged commit 73249e0 into lycheeverse:master Sep 30, 2025
6 checks passed
@mre mre mentioned this pull request Sep 30, 2025
This was referenced Oct 21, 2025
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.

2 participants