From cdef0b75a8ed2eb4ca1f789b61d82b69d40ff7cf Mon Sep 17 00:00:00 2001 From: NotZippy Date: Wed, 24 Oct 2018 10:23:09 -0700 Subject: [PATCH] Added ability to readback output from command line Updated readme --- README.md | 28 ++++++++++++++++++++++++++++ harness/app.go | 21 ++++++++++++++++++--- harness/harness.go | 3 +++ utils/error.go | 9 +++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ae8e171..bf7a27d 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,31 @@ Create a new application ```commandline revel new my/app ``` + +## Community + +* [Gitter](https://gitter.im/revel/community) +* [StackOverflow](http://stackoverflow.com/questions/tagged/revel) + + +## Learn More + +* [Manual, Samples, Godocs, etc](http://revel.github.io) +* [Apps using Revel](https://github.com/revel/revel/wiki/Apps-in-the-Wild) +* [Articles Featuring Revel](https://github.com/revel/revel/wiki/Articles) + +## Contributing + +* [Contributing Code Guidelines](https://github.com/revel/revel/blob/master/CONTRIBUTING.md) +* [Revel Contributors](https://github.com/revel/revel/graphs/contributors) + +## Contributors + +[![](https://sourcerer.io/fame/notzippy/revel/cmd/images/0)](https://sourcerer.io/fame/notzippy/revel/cmd/links/0) +[![](https://sourcerer.io/fame/notzippy/revel/cmd/images/1)](https://sourcerer.io/fame/notzippy/revel/cmd/links/1) +[![](https://sourcerer.io/fame/notzippy/revel/cmd/images/2)](https://sourcerer.io/fame/notzippy/revel/cmd/links/2) +[![](https://sourcerer.io/fame/notzippy/revel/cmd/images/3)](https://sourcerer.io/fame/notzippy/revel/cmd/links/3) +[![](https://sourcerer.io/fame/notzippy/revel/cmd/images/4)](https://sourcerer.io/fame/notzippy/revel/cmd/links/4) +[![](https://sourcerer.io/fame/notzippy/revel/cmd/images/5)](https://sourcerer.io/fame/notzippy/revel/cmd/links/5) +[![](https://sourcerer.io/fame/notzippy/revel/cmd/images/6)](https://sourcerer.io/fame/notzippy/revel/cmd/links/6) +[![](https://sourcerer.io/fame/notzippy/revel/cmd/images/7)](https://sourcerer.io/fame/notzippy/revel/cmd/links/7) diff --git a/harness/app.go b/harness/app.go index beb11ad..1ae5f81 100644 --- a/harness/app.go +++ b/harness/app.go @@ -60,7 +60,7 @@ func NewAppCmd(binPath string, port int, runMode string, paths *model.RevelConta // Start the app server, and wait until it is ready to serve requests. func (cmd AppCmd) Start(c *model.CommandConfig) error { - listeningWriter := &startupListeningWriter{os.Stdout, make(chan bool), c} + listeningWriter := &startupListeningWriter{os.Stdout, make(chan bool), c, &bytes.Buffer{}} cmd.Stdout = listeningWriter utils.Logger.Info("Exec app:", "path", cmd.Path, "args", cmd.Args, "dir", cmd.Dir, "env", cmd.Env) utils.CmdInit(cmd.Cmd, c.AppPath) @@ -70,8 +70,11 @@ func (cmd AppCmd) Start(c *model.CommandConfig) error { select { case exitState := <-cmd.waitChan(): - println("Revel proxy is listening, point your browser to :", c.Run.Port) - return errors.New("revel/harness: app died reason: " + exitState) + fmt.Println("Startup failure view previous messages, \n Proxy is listening :", c.Run.Port) + err := utils.NewError("","Revel Run Error", "starting your application there was an exception. See terminal output, " + exitState,"") + // TODO pretiffy command line output + // err.MetaError = listeningWriter.getLastOutput() + return err case <-time.After(60 * time.Second): println("Revel proxy is listening, point your browser to :", c.Run.Port) @@ -160,8 +163,10 @@ type startupListeningWriter struct { dest io.Writer notifyReady chan bool c *model.CommandConfig + buffer *bytes.Buffer } +// Writes to this output stream func (w *startupListeningWriter) Write(p []byte) (int, error) { if w.notifyReady != nil && bytes.Contains(p, []byte("Revel engine is listening on")) { w.notifyReady <- true @@ -173,5 +178,15 @@ func (w *startupListeningWriter) Write(p []byte) (int, error) { w.notifyReady = nil } } + if w.notifyReady!=nil { + w.buffer.Write(p) + } return w.dest.Write(p) } + +// Returns the cleaned output from the response +// TODO clean the response more +func (w *startupListeningWriter) getLastOutput() string { + return w.buffer.String() +} + diff --git a/harness/harness.go b/harness/harness.go index 1b00776..546016e 100644 --- a/harness/harness.go +++ b/harness/harness.go @@ -231,6 +231,9 @@ func (h *Harness) Refresh() (err *utils.Error) { h.app.Port = h.port if err2 := h.app.Cmd(h.runMode).Start(h.config); err2 != nil { utils.Logger.Error("Could not start application", "error", err2) + if err,k :=err2.(*utils.Error);k { + return err + } return &utils.Error{ Title: "App failed to start up", Description: err2.Error(), diff --git a/utils/error.go b/utils/error.go index 121590b..e03e1f3 100644 --- a/utils/error.go +++ b/utils/error.go @@ -23,6 +23,15 @@ type ( IsError bool } ) +// Return a new error object +func NewError(source, title,path,description string) *Error { + return &Error { + SourceType:source, + Title:title, + Path:path, + Description:description, + } +} // Creates a link based on the configuration setting "errors.link" func (e *Error) SetLink(errorLink string) {