Fix widespread double JSON encoding bug in daemon RPC calls (bd-1048, bd-4ec8)
Multiple CLI commands had a systematic bug where ResolveID responses were
incorrectly converted using string(resp.Data) instead of json.Unmarshal.
Since resp.Data is json.RawMessage (already JSON-encoded), this preserved
the JSON quotes, causing IDs to become "bd-1048" instead of bd-1048.
When re-marshaled for subsequent RPC calls, these became double-quoted
("\"bd-1048\""), causing database lookups to fail.
Bugs fixed:
1. Nil pointer dereference in handleShow - added nil check after GetIssue
2. Double JSON encoding in 12 locations across 4 commands:
- bd show (3 instances in show.go)
- bd dep add/remove/tree (5 instances in dep.go)
- bd label add/remove/list (3 instances in label.go)
- bd reopen (1 instance in reopen.go)
All instances replaced string(resp.Data) with proper json.Unmarshal.
Removed debug logging added during investigation.
Tested: All affected commands now work correctly with daemon mode.
This commit is contained in:
@@ -178,9 +178,7 @@ func (s *Server) handleSignals() {
|
||||
}
|
||||
|
||||
func (s *Server) handleConnection(conn net.Conn) {
|
||||
fmt.Fprintf(os.Stderr, "Debug: handleConnection started (bd-1048)\n")
|
||||
defer func() {
|
||||
fmt.Fprintf(os.Stderr, "Debug: handleConnection closing (bd-1048)\n")
|
||||
_ = conn.Close()
|
||||
}()
|
||||
|
||||
@@ -196,19 +194,15 @@ func (s *Server) handleConnection(conn net.Conn) {
|
||||
writer := bufio.NewWriter(conn)
|
||||
|
||||
for {
|
||||
fmt.Fprintf(os.Stderr, "Debug: waiting for request (bd-1048)\n")
|
||||
// Set read deadline for the next request
|
||||
if err := conn.SetReadDeadline(time.Now().Add(s.requestTimeout)); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Debug: SetReadDeadline error: %v (bd-1048)\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
line, err := reader.ReadBytes('\n')
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Debug: ReadBytes error: %v (bd-1048)\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Debug: received request line (bd-1048)\n")
|
||||
|
||||
var req Request
|
||||
if err := json.Unmarshal(line, &req); err != nil {
|
||||
@@ -219,18 +213,14 @@ func (s *Server) handleConnection(conn net.Conn) {
|
||||
s.writeResponse(writer, resp)
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Debug: parsed request operation: %s (bd-1048)\n", req.Operation)
|
||||
|
||||
// Set write deadline for the response
|
||||
if err := conn.SetWriteDeadline(time.Now().Add(s.requestTimeout)); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Debug: SetWriteDeadline error: %v (bd-1048)\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
resp := s.handleRequest(&req)
|
||||
fmt.Fprintf(os.Stderr, "Debug: handleRequest returned, writing response (bd-1048)\n")
|
||||
s.writeResponse(writer, resp)
|
||||
fmt.Fprintf(os.Stderr, "Debug: response written (bd-1048)\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user