Finished graceful terminal failure

Mikayla Maki created

Change summary

assets/settings/default.json    |  8 ++++----
crates/gpui/src/app.rs          | 11 +++++++----
crates/terminal/src/modal.rs    |  5 +++--
crates/terminal/src/terminal.rs |  3 ++-
4 files changed, 16 insertions(+), 11 deletions(-)

Detailed changes

assets/settings/default.json 🔗

@@ -102,10 +102,10 @@
         //
         "working_directory": "current_project_directory",
         //Any key-value pairs added to this list will be added to the terminal's
-        //enviroment. Use `:` to seperate multiple values, not multiple list items
-        "env": [
-            //["KEY", "value1:value2"]
-        ]
+        //enviroment. Use `:` to seperate multiple values.
+        "env": {
+            //"KEY": "value1:value2"
+        }
         //Set the terminal's font size. If this option is not included,
         //the terminal will default to matching the buffer's font size.
         //"font_size": "15"

crates/gpui/src/app.rs 🔗

@@ -1970,10 +1970,13 @@ impl MutableAppContext {
             for model_id in dropped_models {
                 self.subscriptions.lock().remove(&model_id);
                 self.observations.lock().remove(&model_id);
-                let mut model = self.cx.models.remove(&model_id).unwrap();
-                model.release(self);
-                self.pending_effects
-                    .push_back(Effect::ModelRelease { model_id, model });
+                //Model handles and IDs may have been created to instantiate a model without
+                //finishing successfully (`try_add_model()`)
+                if let Some(mut model) = self.cx.models.remove(&model_id) {
+                    model.release(self);
+                    self.pending_effects
+                        .push_back(Effect::ModelRelease { model_id, model });
+                }
             }
 
             for (window_id, view_id) in dropped_views {

crates/terminal/src/modal.rs 🔗

@@ -1,4 +1,5 @@
 use gpui::{ModelHandle, ViewContext};
+use util::ResultExt;
 use workspace::Workspace;
 
 use crate::{get_wd_for_workspace, DeployModal, Event, Terminal, TerminalConnection};
@@ -26,9 +27,9 @@ pub fn deploy_modal(workspace: &mut Workspace, _: &DeployModal, cx: &mut ViewCon
         if let Some(closed_terminal_handle) = workspace.toggle_modal(cx, |workspace, cx| {
             let wd = get_wd_for_workspace(workspace, cx);
 
-            //TODO: Anything other than crash.
+            //TODO: Create a 'failed to launch' view which prints the error and config details.
             let this = cx
-                .add_option_view(|cx| Terminal::new(wd, true, cx).ok())
+                .add_option_view(|cx| Terminal::new(wd, true, cx).log_err())
                 .unwrap();
 
             let connection_handle = this.read(cx).connection.clone();

crates/terminal/src/terminal.rs 🔗

@@ -17,6 +17,7 @@ use project::{LocalWorktree, Project, ProjectPath};
 use settings::{Settings, WorkingDirectory};
 use smallvec::SmallVec;
 use std::path::{Path, PathBuf};
+use util::ResultExt;
 use workspace::{Item, Workspace};
 
 use crate::terminal_element::TerminalEl;
@@ -157,7 +158,7 @@ impl Terminal {
     ///Create a new Terminal in the current working directory or the user's home directory
     fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) {
         let wd = get_wd_for_workspace(workspace, cx);
-        if let Some(view) = cx.add_option_view(|cx| Terminal::new(wd, false, cx).ok()) {
+        if let Some(view) = cx.add_option_view(|cx| Terminal::new(wd, false, cx).log_err()) {
             workspace.add_item(Box::new(view), cx);
         }
     }