diff options
author | Jason Cox <me@jasoncarloscox.com> | 2024-02-22 20:25:14 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-04-13 21:46:33 +0200 |
commit | 8312b46f144cc1bcf5b6838854df2a9b167c1c3a (patch) | |
tree | 9a1955f37f5ed3f540ee00419d75a727e2ae299e /main.go | |
parent | 941e2e9e7de058f9e6e10efab1ece8be4188468e (diff) | |
download | aerc-8312b46f144cc1bcf5b6838854df2a9b167c1c3a.tar.gz |
ipc: improve error handling
Detect error responses in addition to errors connecting, sending the
request, and receiving the response.
If an error occurs when retrying the IPC call, keep the new aerc
instance running and simply show the error. We already know (due to the
initial failed IPC call) that no other aerc instance is running. Keeping
the new instance open also improves the visibility of the error in some
cases, such as when clicking on a malformed mailto link causes a new
aerc instance to open.
Signed-off-by: Jason Cox <me@jasoncarloscox.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -158,14 +158,16 @@ func main() { if err != nil { die("%s", err) } - retryExec := false + if len(opts.Command) > 0 { - err := ipc.ConnectAndExec(opts.Command) + response, err := ipc.ConnectAndExec(opts.Command) if err == nil { + if response.Error != "" { + fmt.Printf("response: %s\n", response.Error) + } return // other aerc instance takes over } // continue with setting up a new aerc instance and retry after init - retryExec = true } err = config.LoadConfigFromFile( @@ -212,18 +214,25 @@ func main() { enableIpc := func() { startupDone() - if !retryExec { + if len(opts.Command) == 0 { return } // retry execution - err := ipc.ConnectAndExec(opts.Command) + response, err := ipc.ConnectAndExec(opts.Command) + var errMsg string if err != nil { - fmt.Fprintf(os.Stderr, "Failed to communicate to aerc: %v\n", err) - err = app.CloseBackends() - if err != nil { - log.Warnf("failed to close backends: %v", err) - } - os.Exit(1) + errMsg = err.Error() + } else { + errMsg = response.Error + } + + if errMsg != "" { + // no other aerc instance is running, so let + // this one stay running but show the error + errMsg = fmt.Sprintf("Startup command (%s) failed: %s\n", + strings.Join(opts.Command, " "), errMsg) + log.Errorf(errMsg) + app.PushError(errMsg) } } |