zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.62k stars 3.04k forks source link

Dart extension crash #10352

Closed flukejones closed 7 months ago

flukejones commented 7 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Install dart extension as suggested by Zed on opening a dart file.

Environment

Zed: v1.0.0 (Zed Dev 4151ba13a138cef88fabb053119a507c15d49271) OS: Linux 1.0.0 Memory: 31 GiB Architecture: x86_64

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

Thread "main" panicked with "range end index 267037 out of range for slice of length 253952" at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-environ-19.0.0/src/component/translate.rs:537:46
   0: Zed::init_panic_hook::{{closure}}
             at crates/zed/src/main.rs:674:29
   1: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/alloc/src/boxed.rs:2029:9
      std::panicking::rust_panic_with_hook
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:785:13
   2: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:659:13
   3: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/sys_common/backtrace.rs:171:18
   4: rust_begin_unwind
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:647:5
   5: core::panicking::panic_fmt
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:72:14
   6: core::slice::index::slice_end_index_len_fail_rt
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/slice/index.rs:76:5
      core::slice::index::slice_end_index_len_fail
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/slice/index.rs:68:9
   7: <core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/slice/index.rs:394:13
      core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/slice/index.rs:18:9
      wasmtime_environ::component::translate::Translator::translate_payload
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-environ-19.0.0/src/component/translate.rs:537:46
   8: wasmtime_environ::component::translate::Translator::translate
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-environ-19.0.0/src/component/translate.rs:329:19
   9: wasmtime::compile::build_component_artifacts
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-19.0.0/src/compile.rs:127:9
      wasmtime::runtime::component::component::Component::from_binary
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-19.0.0/src/runtime/component/component.rs:234:41
  10: extension::wasm_host::WasmHost::load_extension::{{closure}}
             at crates/extension/src/wasm_host.rs:114:29
  11: extension::ExtensionStore::extensions_updated::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at crates/extension/src/extension_store.rs:1086:26
      extension::ExtensionStore::extensions_updated::{{closure}}::{{closure}}
             at crates/extension/src/extension_store.rs:1091:18
  12: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/future/future.rs:124:9
      <async_task::runnable::Builder<M>::spawn_local::Checked<F> as core::future::future::Future>::poll
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/runnable.rs:455:26
      async_task::raw::RawTask<F,T,S,M>::run
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/raw.rs:557:17
  13: async_task::runnable::Runnable<M>::run
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/runnable.rs:781:18
      gpui::platform::linux::x11::client::X11Client::new::{{closure}}
             at crates/gpui/src/platform/linux/x11/client.rs:84:26
      <core::cell::RefCell<calloop::sources::DispatcherInner<S,F>> as calloop::sources::EventDispatcher<Data>>::process_events::{{closure}}
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/mod.rs:327:61
      <calloop::sources::channel::Channel<T> as calloop::sources::EventSource>::process_events::{{closure}}
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/channel.rs:187:32
      <calloop::sources::ping::eventfd::PingSource as calloop::sources::EventSource>::process_events::{{closure}}
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/ping/eventfd.rs:138:21
      <calloop::sources::generic::Generic<F,E> as calloop::sources::EventSource>::process_events
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/generic.rs:290:9
      <calloop::sources::ping::eventfd::PingSource as calloop::sources::EventSource>::process_events
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/ping/eventfd.rs:127:9
      <calloop::sources::channel::Channel<T> as calloop::sources::EventSource>::process_events
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/channel.rs:184:9
      <core::cell::RefCell<calloop::sources::DispatcherInner<S,F>> as calloop::sources::EventDispatcher<Data>>::process_events
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/mod.rs:326:9
  14: calloop::loop_logic::EventLoop<Data>::dispatch_events
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/loop_logic.rs:445:31
      calloop::loop_logic::EventLoop<Data>::dispatch
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/loop_logic.rs:559:9
      calloop::loop_logic::EventLoop<Data>::run
             at /home/luke/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/loop_logic.rs:596:13
      <gpui::platform::linux::wayland::client::WaylandClient as gpui::platform::linux::platform::LinuxClient>::run
             at crates/gpui/src/platform/linux/wayland/client.rs:310:9
  15: gpui::platform::linux::platform::<impl gpui::platform::Platform for P>::run
             at crates/gpui/src/platform/linux/platform.rs:178:9
  16: gpui::app::App::run
             at crates/gpui/src/app.rs:142:9
  17: Zed::main
             at crates/zed/src/main.rs:160:5
  18: core::ops::function::FnOnce::call_once
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:250:5
      std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/sys_common/backtrace.rs:155:18
  19: std::rt::lang_start::{{closure}}
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/rt.rs:166:18
  20: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:284:13
      std::panicking::try::do_call
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:554:40
      std::panicking::try
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:518:19
      std::panic::catch_unwind
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/rt.rs:148:48
      std::panicking::try::do_call
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:554:40
      std::panicking::try
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:518:19
      std::panic::catch_unwind
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/rt.rs:148:20
  21: main
  22: __libc_start_call_main
  23: __libc_start_main_impl
  24: _start
pedrosoares commented 7 months ago

Same problem here.

To disable the failing extension just remove the part bellow from the file ~/Library/Application\ Support/Zed/extensions/index.json

"dart": {
      "manifest": {
        "id": "dart",
        "name": "Dart",
        "version": "0.0.1",
        "schema_version": 1,
        "description": "Dart support.",
        "repository": "https://github.com/zed-industries/zed",
        "authors": [
          "Abdullah Alsigar <abdullah.alsigar@gmail.com>",
          "Flo <flo80@users.noreply.github.com>"
        ],
        "lib": {
          "kind": "Rust",
          "version": "0.0.6"
        },
        "themes": [],
        "languages": [
          "languages/dart"
        ],
        "grammars": {
          "dart": {
            "repository": "https://github.com/agent3bood/tree-sitter-dart",
            "rev": "48934e3bf757a9b78f17bdfaa3e2b4284656fdc7"
          }
        },
        "language_servers": {
          "dart": {
            "language": "Dart"
          }
        }
      },
      "dev": false
    },

Environment

Zed: Zed 0.129.2 OS: Mac Os Sonoma 14.4 Memory: 32 GiB Architecture: x86_64

maxdeviant commented 7 months ago

@flukejones Do you see the same crash if you install the Dart extension using "Install Dev Extension" and pointing to extensions/dart in the Zed repo?

maxbrunsfeld commented 7 months ago

For anyone who is experiencing this crash (@flukejones, @pedrosoares) could you share the content of the following file?

~/Library/Application Support/Zed/extensions/installed/dart/extension.wasm

From the panic, it looks like the installed wasm file is somehow invalid. I'm curious if I can reproduce the problem if I have the same wasm file as you.

maxbrunsfeld commented 7 months ago

Ok, never mind, we have found a way of reproducing the bug, by truncating a WASM file at a certain position.

PedroSolares commented 7 months ago

@maxbrunsfeld I did a build from master (26299fb8c997d78ee1fdd45a75347f2db2131bff) and error log was the fallowing:

[2024-04-10T12:16:07-03:00 ERROR util] crates/extension/src/extension_store.rs:1093: failed to load wasm extension dart

Caused by:
    unexpected end-of-file (at offset 0x2c684)

I did head and tail this file ~/Library/Application Support/Zed/extensions/installed/dart/extension.wasm:

Head

qtextmethofunction
                  constructorfielvariableclass  interfacemodulpropertyunitvalueenumkeywordsnippetcolorfile  referencefolder
                                                                                                                               enum-membeconstantstructevenoperatortype-parameterotherzcompletion-kindq
plain-textsnippetotherzinsert-text-formatkskkrlabelsdetailkindinsert-text-format
completionqilemodule    namespacepackageclassmethopropertyfield
                                                               constructorenum  interfacfunctiovariablconstantstringnumberbooleanarrayobjectkeynull
                                                                                                                                                   enum-memberstructevenoperatortype-parameterotherz
                                                                                                                                                                                                    symbol-kind rkind
namessymbol

zed:extension/lsp$Bossp@get-environment
wasi:cli/environment@0.2.0Bj@statusexit
Berrorli/exit@0.2.0
wasi:io/error@0.2.0
output-streamerroriqlast-operation-failedclosed
                                               stream-error
                                                           input-streamhjw@sel![method]output-stream.check-write    p}j@selcontents

ethod]output-stream.write
                         .[method]output-stream.blocking-write-and-flush
                                                                        @self
                                                                             $[method]output-stream.blocking-flush

Tail

get-stderr
get-stderr  exit
exit    get-stdin       get-stdin!
get-stdou?
get-stdout"
           __main_module__envwasi:filesystem/preopens@0.2.0asi:filesystem/types@0.2.0wasi:io/error@0.2.wasi:io/streams@0.2.0    wasi:cli/environment@0.2.0
wasi:cli/stderr@0.2.0
                     wasi:cli/exit@0.2.0
wasi:cli/stdout@0.2.0>cabi_export_realloccabi_import_reallo$imports

get-directories
$(  #[method]descriptor.write-via-stream    )   $[method]descriptor.append-via-stream
    ethod]descriptor.get-type
                                    [method]descriptor.stat
(       #[method]descriptor.metadata-hash-at    filesystem-error-cod&![method]output-stream.check-writ ethod]output-stream.writ3.[method]output-stream.blocking-write-and-flus)$[method]output-stream.blocking-flusget-environment
$fd_write
         environ_getenviron_sizes_getfd_prestat_getfd_prestat_dir_namepath_filestat_get proc_exit$imports0%1&2'3(4)5*6+7,8-9.10/11012113214315416517618719820921:22;@init-extensio<9
                                                                                                                                                                                    init-extension(j"s@language-server-idworktree1:Clanguage-server-command!cabi_post_lan=uage-server-command
 >;
?  language-server-command(j$s@language-server-idworktree1<a&language-server-initialization-options0cabi_post_language-server-initialization-options
 @=
A  ,&language-server-initialization-optionsc'language-server-workspace-configuration1cabi_post_language-server-workspace-configuration
 B=
   -'language-server-workspace-configurationpk-p?j?s@language-server-ids
C                                                                       completions>?Alabels-for-completions cabi_post_labels-for-completions
 DB
E  labels-for-completions&p@language-server-idssymbols??9labels-for-symbolscabi_post_labels-for-symbols
 FD
   labels-for-symbols/  producers
wit-component0.201.0%    

My internet connection it is unstable currently, probably downloaded the file partialy?

maxbrunsfeld commented 7 months ago

We opened a Wasmtime issue for this bug, and have added a workaround for it in Zed. https://github.com/bytecodealliance/wasmtime/issues/8322

maxbrunsfeld commented 7 months ago

In the meantime, you should try reinstalling the Dart extension. It looks like your download was partially corrupted.

pedrosoares commented 7 months ago

In the meantime, you should try reinstalling the Dart extension. It looks like your download was partially corrupted.

Can confirm, it works.

JosephTLyons commented 7 months ago

The fix for this just went out in v0.130.5.

flukejones commented 7 months ago

Sorry about not following up sooner (I'm UTC+12). Excellent work y'all, thank you.