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

[bug] FileDialogBuilder::new().set_directory("").pick_file() crashes on macOS #5564

Closed
algernon opened this issue Nov 7, 2022 · 3 comments
Closed
Labels
status: needs triage This issue needs to triage, applied to new issues status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes type: bug

Comments

@algernon
Copy link

algernon commented Nov 7, 2022

Describe the bug

While building an app with Tauri, I ran into an issue on macOS, where trying to open a file selection dialog (save or open, didn't matter) crashed my application with a backtrace.

A little bit of debugging revealed that my app was setting the directory for the selection dialog to "" (an empty string). This worked fine on Linux, which just defaulted to the current directory. But on macOS, this led to the application panicking.

Reproduction

  1. Write a small app that has this kind of code:
use tauri::api::dialog::blocking::FileDialogBuilder;

let filename = FileDialogBuilder::new().set_directory("").pick_file();
  1. Try opening the dialog.
  2. See a long and scary backtrace after the application crashes.

Same problem exists with .save_file() too, by the way.

Expected behavior

I'd expect this to not crash, but default to either the home directory, or the current dir.

Platform and versions

Environment
  › OS: Mac OS 12.4.0 X64
  › Node.js: 18.7.0
  › npm: 8.15.0
  › pnpm: Not installed!
  › yarn: 1.22.19
  › rustup: 1.25.1
  › rustc: 1.63.0
  › cargo: 1.63.0
  › Rust toolchain: stable-aarch64-apple-darwin 

Packages
  › @tauri-apps/cli [NPM]: 1.1.1

Stack trace

thread 'main' panicked at 'Attempted to construct an Id from a null pointer', /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc_id-0.1.1/src/id.rs:62:9
stack backtrace:
   0:        0x101f83fb4 - std::backtrace_rs::backtrace::libunwind::trace::hd589abd6c35ac4ad
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x101f83fb4 - std::backtrace_rs::backtrace::trace_unsynchronized::h98ffcaaa5ca3fa1b
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x101f83fb4 - std::sys_common::backtrace::_print_fmt::h6d737d3ee2f9b02c
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:66:5
   3:        0x101f83fb4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h188b7ef1c7993e78
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:45:22
   4:        0x101fa23a0 - core::fmt::write::he84a3004e7af3f34
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:1197:17
   5:        0x101f7d4f8 - std::io::Write::write_fmt::h9370b50affaab0be
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/io/mod.rs:1672:15
   6:        0x101f85b3c - std::sys_common::backtrace::_print::h6a312acaf6239500
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:48:5
   7:        0x101f85b3c - std::sys_common::backtrace::print::h8d70f4e1fc358fa6
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:35:9
   8:        0x101f85b3c - std::panicking::default_hook::{{closure}}::hc074f8023cce83ca
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:295:22
   9:        0x101f858a4 - std::panicking::default_hook::hef854b51b9b79ff2
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:314:9
  10:        0x101f85fd4 - std::panicking::rust_panic_with_hook::h1e59e224d558a492
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:698:17
  11:        0x101a4cf0c - std::panicking::begin_panic::{{closure}}::hd7ccb52002b44bae
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:617:9
  12:        0x101a4d3b0 - std::sys_common::backtrace::__rust_end_short_backtrace::h47584734270620b5
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:138:18
  13:        0x101fba7d8 - std::panicking::begin_panic::h5a50dd77523cb2eb
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:616:12
  14:        0x101a22fd0 - objc_id::id::Id<T,O>::from_retained_ptr::h3b8de7185a7c5bb4
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc_id-0.1.1/src/id.rs:62:9
  15:        0x101a13db0 - rfd::backend::macos::utils::url::INSURL::file_url_with_path::h078672597051761f
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/utils/url.rs:12:18
  16:        0x101a34bf4 - rfd::backend::macos::file_dialog::panel_ffi::Panel::set_path::h038817bd4a5bc39a
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/file_dialog/panel_ffi.rs:109:27
  17:        0x101a35b00 - rfd::backend::macos::file_dialog::panel_ffi::Panel::build_pick_file::hf95f35bbcf24a1de
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/file_dialog/panel_ffi.rs:168:13
  18:        0x101a112b0 - rfd::backend::macos::file_dialog::<impl rfd::backend::AsyncFilePickerDialogImpl for rfd::file_dialog::FileDialog>::pick_file_async::{{closure}}::h30574e1ad269757f
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/file_dialog.rs:56:21
  19:        0x101a47f78 - rfd::backend::macos::modal_future::ModalFuture<R,D>::new::{{closure}}::h4318f8752de53656
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/rfd-0.10.0/src/backend/macos/modal_future.rs:81:33
  20:        0x101a1dc0c - dispatch::queue::Queue::exec_sync::{{closure}}::hccb2d3be5e15c65c
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/dispatch-0.2.0/src/queue.rs:142:36
  21:        0x101a33490 - dispatch::context_and_sync_function::work_read_closure::hae182b18f543294f
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/dispatch-0.2.0/src/lib.rs:110:9
  22:        0x1c23001b4 - <unknown>
  23:        0x1c230f4ec - <unknown>
  24:        0x1c23001b4 - <unknown>
  25:        0x1c230e6cc - <unknown>
  26:        0x1c230e31c - <unknown>
  27:        0x1c25d2a1c - <unknown>
  28:        0x1c258fca8 - <unknown>
  29:        0x1c258eb24 - <unknown>
  30:        0x1cb1c7338 - <unknown>
  31:        0x1cb1c70b4 - <unknown>
  32:        0x1cb1c6e68 - <unknown>
  33:        0x1c50f578c - <unknown>
  34:        0x1c50f4084 - <unknown>
  35:        0x1c50e6250 - <unknown>
  36:        0x101a328c8 - <() as objc::message::MessageArguments>::invoke::h7351f9ee3899afa6
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:128:17
  37:        0x101a3fd8c - objc::message::platform::send_unverified::{{closure}}::hdcacd62d6f78b8a0
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:27:9
  38:        0x101a309ac - objc_exception::try::{{closure}}::hc21847e495c20f41
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc_exception-0.1.2/src/lib.rs:68:31
  39:        0x101a2d3cc - objc_exception::try_no_ret::try_objc_execute_closure::h6f87d4b5c7b4dbc7
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc_exception-0.1.2/src/lib.rs:34:9
  40:        0x101b4810c - RustObjCExceptionTryCatch
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc_exception-0.1.2/extern/exception.m:10:9
  41:        0x101a2c950 - objc_exception::try_no_ret::hed2cf24af698984b
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc_exception-0.1.2/src/lib.rs:44:19
  42:        0x101a2f424 - objc_exception::try::hd54e3c0cd4f36459
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc_exception-0.1.2/src/lib.rs:67:9
  43:        0x101a4bd64 - objc::exception::try::hc67fce05bcbf3457
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc-0.2.7/src/exception.rs:8:5
  44:        0x101a3b7e8 - objc::message::platform::send_unverified::h644a7340685067e9
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:26:5
  45:        0x100f9b268 - objc::message::send_message::ha5f6d03daab64dd6
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:178:5
  46:        0x100f9b268 - tao::platform_impl::platform::event_loop::EventLoop<T>::run_return::h6830cc53f46ca97f
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tao-0.14.0/src/platform_impl/macos/event_loop.rs:188:16
  47:        0x100f9c024 - tao::platform_impl::platform::event_loop::EventLoop<T>::run::h0d7f5128863fe24f
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tao-0.14.0/src/platform_impl/macos/event_loop.rs:155:21
  48:        0x100fb1114 - tao::event_loop::EventLoop<T>::run::hb893b152f75d507a
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tao-0.14.0/src/event_loop.rs:179:5
  49:        0x1011dad38 - <tauri_runtime_wry::Wry<T> as tauri_runtime::Runtime<T>>::run::h40cd0c7f02f2e0eb
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tauri-runtime-wry-0.11.1/src/lib.rs:2051:5
  50:        0x100fe9794 - tauri::app::App<R>::run::h512273e1932049c1
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tauri-1.1.1/src/app.rs:777:5
  51:        0x100fe9af4 - tauri::app::Builder<R>::run::h5093a781ff116062
                               at /Users/algernon/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tauri-1.1.1/src/app.rs:1579:5
  52:        0x100e5334c - puparium::main::h03d62789875d61b5
                               at /Users/algernon/src/keyboardio/Puparium/puparium-shell/src/main.rs:31:5
  53:        0x1010770c0 - core::ops::function::FnOnce::call_once::h43cf6c8530b58a92
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
  54:        0x100f857b0 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd479ae55d684ba56
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:122:18
  55:        0x100e8a9f4 - std::rt::lang_start::{{closure}}::h82c2ea13d2237dd2
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:145:18
  56:        0x101f77a58 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h6091bdce585e0c9c
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:280:13
  57:        0x101f77a58 - std::panicking::try::do_call::h2dde559bd47c537c
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:492:40
  58:        0x101f77a58 - std::panicking::try::h0be0a0414f498150
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:456:19
  59:        0x101f77a58 - std::panic::catch_unwind::h0dbebda9c8fcb6e3
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panic.rs:137:14
  60:        0x101f77a58 - std::rt::lang_start_internal::{{closure}}::h70683b79d9154b98
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:128:48
  61:        0x101f77a58 - std::panicking::try::do_call::h60888734191539e8
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:492:40
  62:        0x101f77a58 - std::panicking::try::h212200e2cf152f8d
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:456:19
  63:        0x101f77a58 - std::panic::catch_unwind::hf4ae91ebdc2dedaf
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panic.rs:137:14
  64:        0x101f77a58 - std::rt::lang_start_internal::h92a00ef694077615
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:128:20
  65:        0x100e8a9bc - std::rt::lang_start::hd536eee45c78eba7
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:144:17
  66:        0x100e53650 - _main
libc++abi: terminating with uncaught foreign exception


### Additional context

_No response_
@algernon algernon added status: needs triage This issue needs to triage, applied to new issues type: bug labels Nov 7, 2022
@amrbashir
Copy link
Member

Why would you want to use an empty str? you should use "." instead.

@algernon
Copy link
Author

algernon commented Nov 7, 2022

Why would you want to use an empty str? you should use "." instead.

Because an empty string is what String defaults to when using the Default derivation. My code was using .set_directory(default_dir.unwrap_or_default()) (where default_dir is Option<String>), because it felt convenient to do that, and worked just fine on Linux (my main development platform).

It's not that I wanted to use an empty string, it just got there through a couple of layers of indirection.

@amrbashir amrbashir added the status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes label Nov 7, 2022
PolyMeilex pushed a commit to PolyMeilex/rfd that referenced this issue Nov 9, 2022
* fix(FileDialog): fallback to current dir if path is empty

ref: tauri-apps/tauri#5564

* changelog entry

* Update file_dialog.rs

* fallback to `None`

* fmt
@amrbashir
Copy link
Member

fixed upstream in rfd crate and will be available once they release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes type: bug
Projects
None yet
Development

No branches or pull requests

2 participants