Skip to content

Commit

Permalink
Merge pull request #65 from mitre/fix-nr-status-checks
Browse files Browse the repository at this point in the history
Construct printout of failed accessions & fail when no accesions to m…
  • Loading branch information
mattrbianchi authored Mar 21, 2018
2 parents 5611980 + 4939c9f commit 37caf86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 1 addition & 3 deletions cmd/fusera/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ func main() {
twig.Debugf("%+v\n", err)
os.Exit(1)
}
fmt.Println("After checking that you do have proper permissions and that the folder exists, try using the unmount command to ensure the folder is not already mounted.")
fmt.Println("Seek out the troubleshooting guide online or contact your IT administrator.")
fmt.Printf("Mounting file system failed: %s\n", err.Error())
fmt.Printf("%s\n", err.Error())
twig.Debugf("%+v\n", err)
os.Exit(1)
}
Expand Down
26 changes: 18 additions & 8 deletions nr/nr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package nr
import (
"bytes"
"encoding/json"
"fmt"
"io"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -104,20 +105,26 @@ func ResolveNames(loc string, ngc []byte, accs map[string]bool) (map[string]Acce
twig.Debugf("Response from Name Resolver API:\n%s", string(j))
}

accessions := sanitize(payload)
accessions, msg, err := sanitize(payload)
if msg != "" && err == nil {
fmt.Println(msg)
}

return accessions, nil
return accessions, err
}

func sanitize(payload []Payload) map[string]Accession {
accs := make(map[string]Accession)
// msg is used to develop a message to the user indicating which accessions did not succeed while keeping err useful for disastrous errors.
func sanitize(payload []Payload) (accs map[string]Accession, msg string, err error) {
errmsg := ""
accs = make(map[string]Accession)
for _, p := range payload {
// OK, so we don't want duplicate ACCs...
// but if we get duplicates, I guess we could union the files given...
// but then we don't want duplicate files...
// fun...
if p.Status != http.StatusOK {
twig.Infof("issue with getting files for %s: %s", p.ID, p.Message)
msg = msg + fmt.Sprintf("issue with accession %s: %s\n", p.ID, p.Message)
errmsg = errmsg + fmt.Sprintf("%s: %d\t%s", p.ID, p.Status, p.Message)
continue
}
// get existing acc or make a new one
Expand All @@ -128,19 +135,22 @@ func sanitize(payload []Payload) map[string]Accession {
}
for _, f := range p.Files {
if f.Link == "" {
twig.Infof("API returned no link for %s", f.Name)
msg = msg + fmt.Sprintf("issue with accession %s: API returned no link for %s\n", p.ID, f.Name)
continue
}
if f.Name == "" {
twig.Infof("API returned no name for file: %s", f)
msg = msg + fmt.Sprintf("issue with accession %s: API returned no name for %s\n", p.ID, f)
continue
}
acc.Files[f.Name] = f
}
// finally finished with acc
accs[acc.ID] = acc
}
return accs
if len(accs) < 1 {
err = errors.Errorf("API returned no mountable accessions\n%s", errmsg)
}
return
}

type Payload struct {
Expand Down

0 comments on commit 37caf86

Please sign in to comment.