|
6 | 6 | "errors" |
7 | 7 | "fmt" |
8 | 8 | "log" |
| 9 | + "log/slog" |
9 | 10 | "strings" |
10 | 11 | "time" |
11 | 12 |
|
@@ -156,9 +157,11 @@ func (s *SQLiteStore) CreatePlan(p *task.Plan) error { |
156 | 157 | // Serialize draft state if present |
157 | 158 | var draftStateJSON interface{} |
158 | 159 | if p.DraftState != nil { |
159 | | - if data, err := json.Marshal(p.DraftState); err == nil { |
160 | | - draftStateJSON = string(data) |
| 160 | + data, err := json.Marshal(p.DraftState) |
| 161 | + if err != nil { |
| 162 | + return fmt.Errorf("marshal draft_state: %w", err) |
161 | 163 | } |
| 164 | + draftStateJSON = string(data) |
162 | 165 | } |
163 | 166 |
|
164 | 167 | if _, err = tx.Exec(` |
@@ -207,7 +210,9 @@ func (s *SQLiteStore) GetPlan(id string) (*task.Plan, error) { |
207 | 210 | } |
208 | 211 | if draftStateJSON.Valid && draftStateJSON.String != "" { |
209 | 212 | var draftState task.PlanDraftState |
210 | | - if err := json.Unmarshal([]byte(draftStateJSON.String), &draftState); err == nil { |
| 213 | + if err := json.Unmarshal([]byte(draftStateJSON.String), &draftState); err != nil { |
| 214 | + slog.Warn("corrupt draft_state JSON", "plan", p.ID, "error", err) |
| 215 | + } else { |
211 | 216 | p.DraftState = &draftState |
212 | 217 | } |
213 | 218 | } |
@@ -257,7 +262,9 @@ func (s *SQLiteStore) ListPlans() ([]task.Plan, error) { |
257 | 262 | } |
258 | 263 | if draftStateJSON.Valid && draftStateJSON.String != "" { |
259 | 264 | var draftState task.PlanDraftState |
260 | | - if err := json.Unmarshal([]byte(draftStateJSON.String), &draftState); err == nil { |
| 265 | + if err := json.Unmarshal([]byte(draftStateJSON.String), &draftState); err != nil { |
| 266 | + slog.Warn("corrupt draft_state JSON", "plan", p.ID, "error", err) |
| 267 | + } else { |
261 | 268 | p.DraftState = &draftState |
262 | 269 | } |
263 | 270 | } |
@@ -459,7 +466,9 @@ func (s *SQLiteStore) GetClarifySession(id string) (*task.ClarifySession, error) |
459 | 466 | session.CreatedAt, _ = time.Parse(time.RFC3339, createdAt) |
460 | 467 | session.UpdatedAt, _ = time.Parse(time.RFC3339, updatedAt) |
461 | 468 | if currentQuestionsJSON.Valid && currentQuestionsJSON.String != "" { |
462 | | - _ = json.Unmarshal([]byte(currentQuestionsJSON.String), &session.CurrentQuestions) |
| 469 | + if err := json.Unmarshal([]byte(currentQuestionsJSON.String), &session.CurrentQuestions); err != nil { |
| 470 | + slog.Warn("corrupt current_questions JSON", "session", session.ID, "error", err) |
| 471 | + } |
463 | 472 | } |
464 | 473 |
|
465 | 474 | return &session, nil |
@@ -571,10 +580,14 @@ func (s *SQLiteStore) ListClarifyTurns(sessionID string) ([]task.ClarifyTurn, er |
571 | 580 | turn.MaxRoundsReached = maxRoundsReachedInt == 1 |
572 | 581 | turn.CreatedAt, _ = time.Parse(time.RFC3339, createdAt) |
573 | 582 | if questionsJSON.Valid && questionsJSON.String != "" { |
574 | | - _ = json.Unmarshal([]byte(questionsJSON.String), &turn.Questions) |
| 583 | + if err := json.Unmarshal([]byte(questionsJSON.String), &turn.Questions); err != nil { |
| 584 | + slog.Warn("corrupt questions JSON", "turn", turn.ID, "error", err) |
| 585 | + } |
575 | 586 | } |
576 | 587 | if answersJSON.Valid && answersJSON.String != "" { |
577 | | - _ = json.Unmarshal([]byte(answersJSON.String), &turn.Answers) |
| 588 | + if err := json.Unmarshal([]byte(answersJSON.String), &turn.Answers); err != nil { |
| 589 | + slog.Warn("corrupt answers JSON", "turn", turn.ID, "error", err) |
| 590 | + } |
578 | 591 | } |
579 | 592 | turns = append(turns, turn) |
580 | 593 | } |
@@ -648,25 +661,39 @@ func scanTaskRow(row taskRowScanner) (task.Task, error) { |
648 | 661 | } |
649 | 662 |
|
650 | 663 | if acJSON.Valid && acJSON.String != "" { |
651 | | - _ = json.Unmarshal([]byte(acJSON.String), &t.AcceptanceCriteria) |
| 664 | + if err := json.Unmarshal([]byte(acJSON.String), &t.AcceptanceCriteria); err != nil { |
| 665 | + slog.Warn("corrupt acceptance_criteria JSON", "task", t.ID, "error", err) |
| 666 | + } |
652 | 667 | } |
653 | 668 | if vsJSON.Valid && vsJSON.String != "" { |
654 | | - _ = json.Unmarshal([]byte(vsJSON.String), &t.ValidationSteps) |
| 669 | + if err := json.Unmarshal([]byte(vsJSON.String), &t.ValidationSteps); err != nil { |
| 670 | + slog.Warn("corrupt validation_steps JSON", "task", t.ID, "error", err) |
| 671 | + } |
655 | 672 | } |
656 | 673 | if keywordsJSON.Valid && keywordsJSON.String != "" { |
657 | | - _ = json.Unmarshal([]byte(keywordsJSON.String), &t.Keywords) |
| 674 | + if err := json.Unmarshal([]byte(keywordsJSON.String), &t.Keywords); err != nil { |
| 675 | + slog.Warn("corrupt keywords JSON", "task", t.ID, "error", err) |
| 676 | + } |
658 | 677 | } |
659 | 678 | if queriesJSON.Valid && queriesJSON.String != "" { |
660 | | - _ = json.Unmarshal([]byte(queriesJSON.String), &t.SuggestedAskQueries) |
| 679 | + if err := json.Unmarshal([]byte(queriesJSON.String), &t.SuggestedAskQueries); err != nil { |
| 680 | + slog.Warn("corrupt suggested_ask_queries JSON", "task", t.ID, "error", err) |
| 681 | + } |
661 | 682 | } |
662 | 683 | if filesJSON.Valid && filesJSON.String != "" { |
663 | | - _ = json.Unmarshal([]byte(filesJSON.String), &t.FilesModified) |
| 684 | + if err := json.Unmarshal([]byte(filesJSON.String), &t.FilesModified); err != nil { |
| 685 | + slog.Warn("corrupt files_modified JSON", "task", t.ID, "error", err) |
| 686 | + } |
664 | 687 | } |
665 | 688 | if expectedFilesJSON.Valid && expectedFilesJSON.String != "" { |
666 | | - _ = json.Unmarshal([]byte(expectedFilesJSON.String), &t.ExpectedFiles) |
| 689 | + if err := json.Unmarshal([]byte(expectedFilesJSON.String), &t.ExpectedFiles); err != nil { |
| 690 | + slog.Warn("corrupt expected_files JSON", "task", t.ID, "error", err) |
| 691 | + } |
667 | 692 | } |
668 | 693 | if gitBaselineJSON.Valid && gitBaselineJSON.String != "" { |
669 | | - _ = json.Unmarshal([]byte(gitBaselineJSON.String), &t.GitBaseline) |
| 694 | + if err := json.Unmarshal([]byte(gitBaselineJSON.String), &t.GitBaseline); err != nil { |
| 695 | + slog.Warn("corrupt git_baseline JSON", "task", t.ID, "error", err) |
| 696 | + } |
670 | 697 | } |
671 | 698 |
|
672 | 699 | return t, nil |
@@ -1144,7 +1171,9 @@ func (s *SQLiteStore) SearchPlans(query string, status task.PlanStatus) ([]task. |
1144 | 1171 | } |
1145 | 1172 | if draftStateJSON.Valid && draftStateJSON.String != "" { |
1146 | 1173 | var draftState task.PlanDraftState |
1147 | | - if err := json.Unmarshal([]byte(draftStateJSON.String), &draftState); err == nil { |
| 1174 | + if err := json.Unmarshal([]byte(draftStateJSON.String), &draftState); err != nil { |
| 1175 | + slog.Warn("corrupt draft_state JSON", "plan", p.ID, "error", err) |
| 1176 | + } else { |
1148 | 1177 | p.DraftState = &draftState |
1149 | 1178 | } |
1150 | 1179 | } |
@@ -1190,7 +1219,9 @@ func (s *SQLiteStore) GetActivePlan() (*task.Plan, error) { |
1190 | 1219 | } |
1191 | 1220 | if draftStateJSON.Valid && draftStateJSON.String != "" { |
1192 | 1221 | var draftState task.PlanDraftState |
1193 | | - if err := json.Unmarshal([]byte(draftStateJSON.String), &draftState); err == nil { |
| 1222 | + if err := json.Unmarshal([]byte(draftStateJSON.String), &draftState); err != nil { |
| 1223 | + slog.Warn("corrupt draft_state JSON", "plan", p.ID, "error", err) |
| 1224 | + } else { |
1194 | 1225 | p.DraftState = &draftState |
1195 | 1226 | } |
1196 | 1227 | } |
|
0 commit comments