Skip to content

Commit 69f09cd

Browse files
author
Scion Agent (harness-journey-inv)
committed
fix: address Gemini PR review feedback on reimport handler and CLI
- Use r.Body != nil && r.Body != http.NoBody instead of r.ContentLength for chunked/HTTP2 compatibility in reimport handler - Add nil check for harness config after GetHarnessConfig lookup - Use cmd.Context() instead of context.Background() in update command - Add nil checks for resp after Hub List calls in both update functions
1 parent db73666 commit 69f09cd

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

cmd/harness_config_update.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func runHarnessConfigUpdate(cmd *cobra.Command, args []string) error {
7272

7373
PrintUsingHub(hubCtx.Endpoint)
7474

75-
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
75+
ctx, cancel := context.WithTimeout(cmd.Context(), 120*time.Second)
7676
defer cancel()
7777

7878
if all {
@@ -91,6 +91,9 @@ func updateSingleHarnessConfig(ctx context.Context, hubCtx *HubContext, name, ur
9191
if err != nil {
9292
return fmt.Errorf("failed to search Hub: %w", err)
9393
}
94+
if resp == nil {
95+
return fmt.Errorf("harness-config %q not found on Hub", name)
96+
}
9497

9598
var match *hubclient.HarnessConfig
9699
for i := range resp.HarnessConfigs {
@@ -144,6 +147,9 @@ func updateAllHarnessConfigs(ctx context.Context, hubCtx *HubContext) error {
144147
if err != nil {
145148
return fmt.Errorf("failed to list harness-configs: %w", err)
146149
}
150+
if resp == nil {
151+
return fmt.Errorf("no harness-configs found")
152+
}
147153

148154
var updated, skipped, failed int
149155
jsonOut := isJSONOutput()

pkg/hub/harness_config_handlers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,9 +719,13 @@ func (s *Server) handleHarnessConfigReimport(w http.ResponseWriter, r *http.Requ
719719
writeErrorFromErr(w, err, "")
720720
return
721721
}
722+
if hc == nil {
723+
NotFound(w, "HarnessConfig")
724+
return
725+
}
722726

723727
var req ReimportHarnessConfigRequest
724-
if r.ContentLength > 0 {
728+
if r.Body != nil && r.Body != http.NoBody {
725729
if err := readJSON(r, &req); err != nil {
726730
BadRequest(w, "Invalid request body: "+err.Error())
727731
return

0 commit comments

Comments
 (0)