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

Program panics on windows 10 with the message 'The system cannot find the file specified.' #68

Closed
UncertainProd opened this issue Apr 11, 2023 · 6 comments · Fixed by #69

Comments

@UncertainProd
Copy link

When I try to run the following example code, it results in the program panicking with the message below:
Code:

fn main() {
    webbrowser::open("http://github.com").unwrap();
}

Error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }'

I'm guessing it could be because my browser is located at C:\Program Files\.....\firefox.exe which has a space in its path.
Maybe that's messing up the command that's being executed?

@amodm
Copy link
Owner

amodm commented Apr 11, 2023

That shouldn't be an issue. Can you enable TRACE level logging for webbrowser, and share the results? One way to do that would be to clone the webbrowser repo, and run cargo test -- --nocapture with RUST_LOG environment variable set to webbrowser=trace (i.e. set RUST_LOG=webbrowser=trace)

@UncertainProd
Copy link
Author

Sure, this is what I got:

running 4 tests
test test_open_chrome ... ignored
test test_open_firefox ... ignored
test test_open_safari ... ignored
test test_open_webpositive ... ignored

test result: ok. 0 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out; finished in 0.01s

     Running tests\common.rs (target\debug\deps\common-367f292cf953440d.exe)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests\test_android.rs (target\debug\deps\test_android-e1f0cfcd8321daf2.exe)

running 3 tests
test tests::test_android ... ignored
test tests::test_existence_default ... ok
test tests::test_non_existence_safari ... ok

test result: ok. 2 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.01s

     Running tests\test_ios.rs (target\debug\deps\test_ios-c7a017635bed60f4.exe)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests\test_macos.rs (target\debug\deps\test_macos-c82337c3f49dc4d7.exe)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests\test_unix.rs (target\debug\deps\test_unix-12f3947abb90d478.exe)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests\test_wasm.rs (target\debug\deps\test_wasm-5934a00bc7ce7ed4.exe)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests\test_windows.rs (target\debug\deps\test_windows-16d2ff4f08590527.exe)

running 7 tests
test tests::test_open_internet_explorer ... ignored
test tests::test_existence_default ... ok
test tests::test_non_existence_safari ... ok
[2023-04-11T11:21:46Z TRACE webbrowser::os] trying to figure out default browser command
[2023-04-11T11:21:46Z TRACE webbrowser::os] trying to figure out default browser command
[2023-04-11T11:21:46Z TRACE webbrowser::os] trying to figure out default browser command
[2023-04-11T11:21:46Z TRACE webbrowser::os] trying to figure out default browser command
[2023-04-11T11:21:46Z TRACE webbrowser::os] default browser command: C:\Program Files\WindowsApps\Mozilla.Firefox_111.0.1.0_x64__n80bbvh6b1yt2\VFS\ProgramFiles\Firefox Package Root\firefox.exe -osint -url "%1"
[2023-04-11T11:21:46Z TRACE webbrowser::os] default browser command: C:\Program Files\WindowsApps\Mozilla.Firefox_111.0.1.0_x64__n80bbvh6b1yt2\VFS\ProgramFiles\Firefox Package Root\firefox.exe -osint -url "%1"
[2023-04-11T11:21:46Z TRACE webbrowser::os] default browser command: C:\Program Files\WindowsApps\Mozilla.Firefox_111.0.1.0_x64__n80bbvh6b1yt2\VFS\ProgramFiles\Firefox Package Root\firefox.exe -osint -url "%1"
[2023-04-11T11:21:46Z TRACE webbrowser::os] default browser command: C:\Program Files\WindowsApps\Mozilla.Firefox_111.0.1.0_x64__n80bbvh6b1yt2\VFS\ProgramFiles\Firefox Package Root\firefox.exe -osint -url "%1"
[2023-04-11T11:21:46Z DEBUG webbrowser::common] background spawn: "C:\\Program" "Files\\WindowsApps\\Mozilla.Firefox_111.0.1.0_x64__n80bbvh6b1yt2\\VFS\\ProgramFiles\\Firefox" "Package" "Root\\firefox.exe" "-osint" "-url" "file:///C:/Programming/Rust/webbrowser-rs/target/tmp/test.1449585646.html"
[2023-04-11T11:21:46Z DEBUG webbrowser::common] background spawn: "C:\\Program" "Files\\WindowsApps\\Mozilla.Firefox_111.0.1.0_x64__n80bbvh6b1yt2\\VFS\\ProgramFiles\\Firefox" "Package" "Root\\firefox.exe" "-osint" "-url" "file:///C:/Programming/Rust/webbrowser-rs/target/tmp/test.2837218721.html"
[2023-04-11T11:21:46Z DEBUG webbrowser::common] background spawn: "C:\\Program" "Files\\WindowsApps\\Mozilla.Firefox_111.0.1.0_x64__n80bbvh6b1yt2\\VFS\\ProgramFiles\\Firefox" "Package" "Root\\firefox.exe" "-osint" "-url" "file:///C:/Programming/Rust/webbrowser-rs/target/tmp/test.283613868.html"
thread 'thread '[2023-04-11T11:21:46Z DEBUG webbrowser::common] background spawn: "C:\\Program" "Files\\WindowsApps\\Mozilla.Firefox_111.0.1.0_x64__n80bbvh6b1yt2\\VFS\\ProgramFiles\\Firefox" "Package" "Root\\firefox.exe" "-osint" "-url" "http://127.0.0.1:60285/windows"
tests::test_local_file_abs_paththread 'tests::test_local_file_rel_path' panicked at 'thread 'tests::test_local_file_uritests::test_open_default' panicked at '' panicked at 'failed to open browser: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }failed to open browser: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }' panicked at 'failed to open browser: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }', ', ', tests\common.rstests\common.rstests\common.rsfailed to open browser: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }:::', 125125125tests\common.rs::::373737

97
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
:test tests::test_local_file_uri ... 36FAILED

test tests::test_local_file_abs_path ... FAILED
test tests::test_local_file_rel_path ... FAILED
test tests::test_open_default ... FAILED

failures:

failures:
    tests::test_local_file_abs_path
    tests::test_local_file_rel_path
    tests::test_local_file_uri
    tests::test_open_default

test result: FAILED. 2 passed; 4 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.05s

error: test failed, to rerun pass `--test test_windows`

@amodm
Copy link
Owner

amodm commented Apr 11, 2023

Thanks. It does seem like it's the space that's causing the issue, but for a different reason than what you might imagine.

Under normal circumstances, the default browser command should've been found as "C:\Program Files\WindowsApps\Mozilla.Firefox_111.0.1.0_x64__n80bbvh6b1yt2\VFS\ProgramFiles\Firefox Package Root\firefox.exe" -osint -url "%1" (notice the quotes for the path to your firefox.exe). But yours is without the quotes, so the command is assumed to be C:\Program.

For example, on my windows sandbox, it's detected as "C:\Program Files\Google\Chrome\Application\chrome.exe" --single-argument %1.

I'll have to debug a little to figure out if this is a common issue. If it is, then I'll have to fix it in this library. If not, then it could be an installation bug at your end. I'm currently not very inclined to believe the latter, but the former is very weird to imagine as well.

I may tag you for some further clarification. Thanks for providing the details till now.

@amodm
Copy link
Owner

amodm commented Apr 11, 2023

@UncertainProd, can you please check if the code in branch fix/issue-68 fixes the issue for you? If yes, I'll merge it and include this fix in the next release.

@UncertainProd
Copy link
Author

Yeah, that seems to work. Thanks!

@amodm
Copy link
Owner

amodm commented Apr 12, 2023

FYI, this is now out as v0.8.9. Thanks for the report & for the help in debugging this.

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 a pull request may close this issue.

2 participants