(response jsonRpcResponse)
| 568 | response := jsonRpcResponse{ |
| 569 | JSONRPC: "2.0", |
| 570 | ID: id, |
| 571 | Error: &rpcError{ |
| 572 | Code: code, |
| 573 | Message: errorMsg, |
| 574 | }, |
| 575 | } |
| 576 | ss.writeResponse(response) |
| 577 | } |
| 578 | |
| 579 | func (ss *stdioServer) writeResponse(response jsonRpcResponse) { |
| 580 | // Marshalled response as single line |
| 581 | responseBytes, err := json.Marshal(response) |
| 582 | if err != nil { |
| 583 | log.Error().Err(err).Msg("Failed to marshal response") |
| 584 | fallback := jsonRpcResponse{ |
| 585 | JSONRPC: "2.0", |
| 586 | ID: response.ID, |
| 587 | Error: &rpcError{ |
| 588 | Code: -32603, |
| 589 | Message: "Internal error: failed to marshal response", |
| 590 | }, |
| 591 | } |
| 592 | responseBytes, err = json.Marshal(fallback) |
| 593 | if err != nil { |
| 594 | log.Error().Err(err).Msg("Failed to marshal fallback response") |
| 595 | return |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | // Write to stdout with newline |
| 600 | fmt.Fprintf(ss.stdout, "%s\n", string(responseBytes)) |
| 601 | |
| 602 | // Log with appropriate fields based on response type |
| 603 | logEvent := log.Debug().Str("id", response.ID.String()) |
| 604 | if response.Error != nil { |
no test coverage detected