Skip to content

Blank rust-project.json file causes RA server to panic. #5139

Closed
@Nashenas88

Description

@Nashenas88

With this kind of folder structure:

.
├── rust-project.json
└── src
    └── main.rs

Where rust-project.json and main.rs are both empty files, the following crash occurs:

Click to expand backtrace
[ERROR rust_analyzer::reload] failed to load workspace: Failed to deserialize json file /home/pfaria/projects/json-rust-projects/empty-json-project/rust-project.json: EOF while parsing a value at line 1 column 0
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', crates/vfs/src/file_set.rs:72:30
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.1485827954.workers.dev-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.1485827954.workers.dev-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1504
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:511
  11: rust_begin_unwind
             at src/libstd/panicking.rs:419
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:111
  13: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:69
  14: vfs::file_set::FileSetConfig::partition
  15: rust_analyzer::reload::SourceRootConfig::partition
  16: rust_analyzer::global_state::GlobalState::process_changes
  17: rust_analyzer::main_loop::<impl rust_analyzer::global_state::GlobalState>::handle_event
  18: rust_analyzer::main_loop::<impl rust_analyzer::global_state::GlobalState>::run
  19: rust_analyzer::main_loop::main_loop
  20: rust_analyzer::main
  21: std::rt::lang_start::{{closure}}
  22: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:52
  23: std::panicking::try::do_call
             at src/libstd/panicking.rs:331
  24: std::panicking::try
             at src/libstd/panicking.rs:274
  25: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  26: std::rt::lang_start_internal
             at src/libstd/rt.rs:51
  27: main
  28: __libc_start_main
  29: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I don't expect proper support for empty files, but in order to fix this I have to completely close VS Code to get the extension back online. It would be nice if it failed gracefully so I could fix project issues without having to restart the editor.

Background: I ran into this when my rust-project.json was generated incorrectly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions