Skip to content
Open
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package godo

import (
"io/ioutil"
"net/http"
)

func HTTPGetString(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(body), nil
}

func MustHTTPGetString(url string) string {
body, err := HTTPGetString(url)
if err != nil {
panic(&mustPanic{
err: err,
})
}
return body
}
6 changes: 6 additions & 0 deletions must.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package godo

type mustPanic struct {
// err is the original error that caused the panic
err error
}
18 changes: 16 additions & 2 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ func (project *Project) debounce(task *Task) bool {

// Run runs a task by name.
func (project *Project) Run(name string) {
project.run(name, name, nil)
err := project.run(name, name, nil)
if err != nil {
fmt.Printf("error running task %s: %v\n", name, err)
}
}

// RunWithEvent runs a task by name and adds FileEvent e to the context.
Expand All @@ -86,7 +89,7 @@ func (project *Project) runWithEvent(name string, logName string, e *watcher.Fil
}

// run runs the project, executing any tasks named on the command line.
func (project *Project) run(name string, logName string, e *watcher.FileEvent) error {
func (project *Project) run(name string, logName string, e *watcher.FileEvent) (err error) {
_, task := project.mustTask(name)
if project.debounce(task) {
return nil
Expand All @@ -96,6 +99,17 @@ func (project *Project) run(name string, logName string, e *watcher.FileEvent) e
return nil
}

// recover any mustPanic's
defer func() {
if p := recover(); p != nil {
mp, ok := p.(*mustPanic)
if !ok {
panic(p)
}
err = mp.err
}
}()

// Run each task including their dependencies.
for _, depName := range task.Dependencies {
namespace, taskName := project.namespaceTaskName(depName)
Expand Down