From 88947053215b8babf8c069158d63c8051a3b7541 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 4 Aug 2021 19:21:27 +0800 Subject: [PATCH] fix: fix crash reported by https://gitee.com/sourcegit/sourcegit/issues/I43UH1 --- src/Commands/Command.cs | 18 ++++++++++++++++-- src/Commands/Config.cs | 3 +-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 6e31d6e7..a35ba598 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -110,7 +110,13 @@ namespace SourceGit.Commands { errs.Add(e.Data); }; - proc.Start(); + try { + proc.Start(); + } catch (Exception e) { + if (!DontRaiseError) Models.Exception.Raise(e.Message); + return false; + } + proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(); @@ -143,7 +149,15 @@ namespace SourceGit.Commands { if (!string.IsNullOrEmpty(Cwd)) start.WorkingDirectory = Cwd; var proc = new Process() { StartInfo = start }; - proc.Start(); + try { + proc.Start(); + } catch (Exception e) { + return new ReadToEndResult() { + Output = "", + Error = e.Message, + IsSuccess = false, + }; + } var rs = new ReadToEndResult(); rs.Output = proc.StandardOutput.ReadToEnd(); diff --git a/src/Commands/Config.cs b/src/Commands/Config.cs index 7b99a99d..19325ffe 100644 --- a/src/Commands/Config.cs +++ b/src/Commands/Config.cs @@ -4,8 +4,7 @@ namespace SourceGit.Commands { /// public class Config : Command { - public Config() { - } + public Config() {} public Config(string repo) { Cwd = repo;