Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: findExecutable "" should return Nothing, like on linux #180

Closed
TerrorJack opened this issue May 29, 2024 · 4 comments · Fixed by #186
Closed

FR: findExecutable "" should return Nothing, like on linux #180

TerrorJack opened this issue May 29, 2024 · 4 comments · Fixed by #186
Labels
type: a-feature-request This is a request for a new feature.

Comments

@TerrorJack
Copy link
Contributor

On Windows, findExecutable "" would throw *** Exception: searchPath: invalid argument (The parameter is incorrect.). However, on Linux it simply returns Nothing. I believe this is a bug and we should align Windows behavior with Linux to also return Nothing.

@hasufell
Copy link
Member

What are the affected versions?

@TerrorJack
Copy link
Contributor Author

directory-1.3.8.4 as shipped in ghc head.

@hasufell
Copy link
Member

I can also reproduce this with directory-1.3.7.1 from GHC-9.4.8. So it is not related to the OsPath migration.

hubot pushed a commit to ghc/ghc that referenced this issue May 31, 2024
hadrian may invoke findExecutable "" at run-time due to a certain
program is not found by configure script. Which is fine and
findExecutable is supposed to return Nothing in this case. However, on
Windows there's a directory bug that throws an exception (see
haskell/directory#180), so we might as well
use a wrapper for findExecutable and handle exceptions gracefully.
hubot pushed a commit to ghc/ghc that referenced this issue May 31, 2024
hadrian may invoke findExecutable "" at run-time due to a certain
program is not found by configure script. Which is fine and
findExecutable is supposed to return Nothing in this case. However, on
Windows there's a directory bug that throws an exception (see
haskell/directory#180), so we might as well
use a wrapper for findExecutable and handle exceptions gracefully.
@Rufflewind
Copy link
Member

This appears to be canonical behavior for the Win32 SearchPathW API:

#include <stdio.h>
#include <windows.h>

int main(void)
{
    wchar_t buffer[512] = {0};
    if (SearchPathW(NULL, L"", L".exe", 512, buffer, NULL) == 0) {
        return GetLastError();
    }
    printf("%ls\n", buffer);
    return 0;
}

This fails with ERROR_INVALID_PARAMETER (87).

Given that the directory implementation of findExecutable has always relied on SearchPathW, this is unlikely a regression and has probably worked this way since the beginning.

I think it is a reasonable feature request though. The SearchPathW seems to handle other kinds of nonsensical strings just fine, except for the empty string.

@Rufflewind Rufflewind added the type: a-feature-request This is a request for a new feature. label Jul 12, 2024
@Rufflewind Rufflewind changed the title findExecutable "" throws on windows but not on linux FR findExecutable "" should return Nothing, like on linux Jul 12, 2024
@Rufflewind Rufflewind changed the title FR findExecutable "" should return Nothing, like on linux FR: findExecutable "" should return Nothing, like on linux Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: a-feature-request This is a request for a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants