Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print a warning if the local application exits early #35

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,11 @@ Run 'dispatch help run' to learn about Dispatch sessions.`, BridgeSession)
}

if err != nil {
if r, ok := logWriter.(io.Reader); ok {
// Dump any buffered logs to stderr in this case.
time.Sleep(100 * time.Millisecond)
_, _ = io.Copy(os.Stderr, r)
}
dumpLogs(logWriter)
return fmt.Errorf("failed to invoke command '%s': %v", strings.Join(args, " "), err)
} else if !signaled && successfulPolls == 0 {
dumpLogs(logWriter)
return fmt.Errorf("command '%s' exited unexpectedly", strings.Join(args, " "))
}
return nil
},
Expand All @@ -330,6 +329,14 @@ Run 'dispatch help run' to learn about Dispatch sessions.`, BridgeSession)
return cmd
}

func dumpLogs(logWriter io.Writer) {
if r, ok := logWriter.(io.Reader); ok {
time.Sleep(100 * time.Millisecond)
_, _ = io.Copy(os.Stderr, r)
_, _ = os.Stderr.Write([]byte{'\n'})
}
}

func poll(ctx context.Context, client *http.Client, url string) (string, *http.Response, error) {
slog.Debug("getting request from Dispatch", "url", url)

Expand Down
Loading