Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com Signed-off-by: Russ T Fugal russ-fugal@smart-knowledge-systems.com
+12
-5
Diff
round #0
+4
-1
knotmirror/xrpc/repo_listBranches.go
+4
-1
knotmirror/xrpc/repo_listBranches.go
···
28
28
repo, err := syntax.ParseATURI(repoQuery)
29
29
if err != nil || repo.RecordKey() == "" {
30
30
writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: fmt.Sprintf("repo parameter invalid: %s", repoQuery)})
31
+
return
31
32
}
32
33
33
34
limit := 50
···
35
36
limit, err = strconv.Atoi(limitQuery)
36
37
if err != nil || limit < 1 || limit > 1000 {
37
38
writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: fmt.Sprintf("limit parameter invalid: %s", limitQuery)})
39
+
return
38
40
}
39
41
}
40
42
···
43
45
cursor, err = strconv.ParseInt(cursorQuery, 10, 64)
44
46
if err != nil || cursor < 0 {
45
47
writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: fmt.Sprintf("cursor parameter invalid: %s", cursorQuery)})
48
+
return
46
49
}
47
50
}
48
51
49
52
out, err := x.listBranches(r.Context(), repo, limit, cursor)
50
53
if err != nil {
51
-
// TODO: better error return
52
54
writeJson(w, http.StatusInternalServerError, atclient.ErrorBody{Name: "InternalServerError", Message: "failed to list branches"})
55
+
return
53
56
}
54
57
writeJson(w, http.StatusOK, out)
55
58
}
+4
-3
knotmirror/xrpc/repo_listLanguages.go
+4
-3
knotmirror/xrpc/repo_listLanguages.go
···
24
24
if err != nil || repo.RecordKey() == "" {
25
25
l.Error("invalid repo at-uri", "err", err)
26
26
writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: fmt.Sprintf("repo parameter invalid: %s", repoQuery)})
27
+
return
27
28
}
28
29
29
30
repoPath, err := x.makeRepoPath(r.Context(), repo)
30
31
if err != nil {
31
32
l.Error("invalid repo identifier", "err", err)
32
-
// TODO: better error return
33
33
writeJson(w, http.StatusInternalServerError, atclient.ErrorBody{Name: "InternalServerError", Message: "invalid repo identifier"})
34
+
return
34
35
}
35
36
36
37
gr, err := git.Open(repoPath, ref)
37
38
if err != nil {
38
39
l.Error("failed to open repository", "err", err)
39
-
// TODO: better error return
40
40
writeJson(w, http.StatusInternalServerError, atclient.ErrorBody{Name: "InternalServerError", Message: "failed to open repository"})
41
+
return
41
42
}
42
43
43
44
ctx, cancel := context.WithTimeout(r.Context(), 1*time.Second)
···
46
47
sizes, err := gr.AnalyzeLanguages(ctx)
47
48
if err != nil {
48
49
l.Error("failed to open repository", "err", err)
49
-
// TODO: better error return
50
50
writeJson(w, http.StatusInternalServerError, atclient.ErrorBody{Name: "InternalServerError", Message: "failed to analyze languages"})
51
+
return
51
52
}
52
53
53
54
langs := sizesToLanguages(sizes)
+4
-1
knotmirror/xrpc/repo_listTags.go
+4
-1
knotmirror/xrpc/repo_listTags.go
···
29
29
repo, err := syntax.ParseATURI(repoQuery)
30
30
if err != nil || repo.RecordKey() == "" {
31
31
writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: fmt.Sprintf("repo parameter invalid: %s", repoQuery)})
32
+
return
32
33
}
33
34
34
35
limit := 50
···
36
37
limit, err = strconv.Atoi(limitQuery)
37
38
if err != nil || limit < 1 || limit > 1000 {
38
39
writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: fmt.Sprintf("limit parameter invalid: %s", limitQuery)})
40
+
return
39
41
}
40
42
}
41
43
···
44
46
cursor, err = strconv.ParseInt(cursorQuery, 10, 64)
45
47
if err != nil || cursor < 0 {
46
48
writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: fmt.Sprintf("cursor parameter invalid: %s", cursorQuery)})
49
+
return
47
50
}
48
51
}
49
52
50
53
out, err := x.listTags(r.Context(), repo, limit, cursor)
51
54
if err != nil {
52
-
// TODO: better error return
53
55
writeJson(w, http.StatusInternalServerError, atclient.ErrorBody{Name: "InternalServerError", Message: "failed to list tags"})
56
+
return
54
57
}
55
58
writeJson(w, http.StatusOK, out)
56
59
}
History
1 round
2 comments
russ-fugal.smart-knowledge-systems.com
submitted
#0
1 commit
expand
collapse
knotmirror/xrpc: add early returns after error responses
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Russ T Fugal <russ-fugal@smart-knowledge-systems.com>
expand 2 comments
closed without merging
Fixes fall-through bug where execution continued after writing error responses