Skip to content

Commit 37caf86

Browse files
authored
Merge pull request #65 from mitre/fix-nr-status-checks
Construct printout of failed accessions & fail when no accesions to m…
2 parents 5611980 + 4939c9f commit 37caf86

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

cmd/fusera/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ func main() {
148148
twig.Debugf("%+v\n", err)
149149
os.Exit(1)
150150
}
151-
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.")
152-
fmt.Println("Seek out the troubleshooting guide online or contact your IT administrator.")
153-
fmt.Printf("Mounting file system failed: %s\n", err.Error())
151+
fmt.Printf("%s\n", err.Error())
154152
twig.Debugf("%+v\n", err)
155153
os.Exit(1)
156154
}

nr/nr.go

+18-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package nr
1515
import (
1616
"bytes"
1717
"encoding/json"
18+
"fmt"
1819
"io"
1920
"mime/multipart"
2021
"net/http"
@@ -104,20 +105,26 @@ func ResolveNames(loc string, ngc []byte, accs map[string]bool) (map[string]Acce
104105
twig.Debugf("Response from Name Resolver API:\n%s", string(j))
105106
}
106107

107-
accessions := sanitize(payload)
108+
accessions, msg, err := sanitize(payload)
109+
if msg != "" && err == nil {
110+
fmt.Println(msg)
111+
}
108112

109-
return accessions, nil
113+
return accessions, err
110114
}
111115

112-
func sanitize(payload []Payload) map[string]Accession {
113-
accs := make(map[string]Accession)
116+
// msg is used to develop a message to the user indicating which accessions did not succeed while keeping err useful for disastrous errors.
117+
func sanitize(payload []Payload) (accs map[string]Accession, msg string, err error) {
118+
errmsg := ""
119+
accs = make(map[string]Accession)
114120
for _, p := range payload {
115121
// OK, so we don't want duplicate ACCs...
116122
// but if we get duplicates, I guess we could union the files given...
117123
// but then we don't want duplicate files...
118124
// fun...
119125
if p.Status != http.StatusOK {
120-
twig.Infof("issue with getting files for %s: %s", p.ID, p.Message)
126+
msg = msg + fmt.Sprintf("issue with accession %s: %s\n", p.ID, p.Message)
127+
errmsg = errmsg + fmt.Sprintf("%s: %d\t%s", p.ID, p.Status, p.Message)
121128
continue
122129
}
123130
// get existing acc or make a new one
@@ -128,19 +135,22 @@ func sanitize(payload []Payload) map[string]Accession {
128135
}
129136
for _, f := range p.Files {
130137
if f.Link == "" {
131-
twig.Infof("API returned no link for %s", f.Name)
138+
msg = msg + fmt.Sprintf("issue with accession %s: API returned no link for %s\n", p.ID, f.Name)
132139
continue
133140
}
134141
if f.Name == "" {
135-
twig.Infof("API returned no name for file: %s", f)
142+
msg = msg + fmt.Sprintf("issue with accession %s: API returned no name for %s\n", p.ID, f)
136143
continue
137144
}
138145
acc.Files[f.Name] = f
139146
}
140147
// finally finished with acc
141148
accs[acc.ID] = acc
142149
}
143-
return accs
150+
if len(accs) < 1 {
151+
err = errors.Errorf("API returned no mountable accessions\n%s", errmsg)
152+
}
153+
return
144154
}
145155

146156
type Payload struct {

0 commit comments

Comments
 (0)