|
657 | 657 | source-type target-type))})) |
658 | 658 |
|
659 | 659 | (defn- record-target-failures! |
660 | | - [failure-ctx syntax target-mid target-eid valid?] |
| 660 | + "Record a failure when a relation command's target lookup or |
| 661 | + validation didn't pan out. Distinguishes three modes: |
| 662 | + - :unknown-target -- mid was given but no report matches. |
| 663 | + - :self-loop -- target resolves to the current report itself |
| 664 | + (a no-op self-reference, common when a new |
| 665 | + bug filed as a reply names its own thread root). |
| 666 | + - :type-mismatch -- target exists but the type constraint fails." |
| 667 | + [failure-ctx syntax target-mid target-eid valid? report-eid] |
661 | 668 | (when failure-ctx |
662 | 669 | (cond |
663 | 670 | (and target-mid (nil? target-eid)) |
664 | 671 | (record-failure! (assoc failure-ctx |
665 | 672 | :reason :unknown-target |
666 | 673 | :audience :author |
667 | 674 | :command (str syntax ": " target-mid))) |
| 675 | + (and target-eid (= target-eid report-eid)) |
| 676 | + (record-failure! (assoc failure-ctx |
| 677 | + :reason :self-loop |
| 678 | + :audience :author |
| 679 | + :command (str syntax ": " target-mid))) |
668 | 680 | (and target-eid (not valid?)) |
669 | 681 | (record-failure! (assoc failure-ctx |
670 | 682 | :reason :type-mismatch |
|
674 | 686 | (defn- apply-related-to! |
675 | 687 | "Pose / retract :related-to relations from a resolved commands map. |
676 | 688 | Independent of report closure state; called from both `apply-lines!` |
677 | | - (open path) and `try-unclosed!` (closed path). Emits failures for |
678 | | - unknown targets, ignores self-loops silently. |
| 689 | + (open path) and `try-unclosed!` (closed path). Records failures |
| 690 | + for unknown targets and self-loops. |
679 | 691 |
|
680 | 692 | Target mids resolve via `report-eid-by-mid` -- root or descendant -- |
681 | 693 | so a mid pointing at any email in a report's thread reaches that |
|
700 | 712 | :audience :author |
701 | 713 | :command (str "Related-to: " mid)))) |
702 | 714 | (= report-eid target-eid) |
703 | | - (log/warn "Related-to: self-loop ignored" mid) |
| 715 | + (do (log/warn (str "Related-to: " mid |
| 716 | + " -- targets the same report (self-loop) -- ignored")) |
| 717 | + (when failure-ctx |
| 718 | + (record-failure! (assoc failure-ctx |
| 719 | + :reason :self-loop |
| 720 | + :audience :author |
| 721 | + :command (str "Related-to: " mid))))) |
704 | 722 | :else |
705 | 723 | (do (rel/pose-if-absent! conn {:from-eid report-eid |
706 | 724 | :to-eid target-eid |
|
985 | 1003 | (doseq [{:keys [resolved syntax target-mid]} rows |
986 | 1004 | :let [tgt-eid (:target-eid resolved) |
987 | 1005 | valid? (:valid? resolved)]] |
988 | | - (record-target-failures! failure-ctx syntax target-mid tgt-eid valid?) |
| 1006 | + (record-target-failures! failure-ctx syntax target-mid tgt-eid valid? report-eid) |
989 | 1007 | (when (and tgt-eid (not valid?)) |
990 | | - (log/warn (str syntax ": type mismatch -- source") |
991 | | - source-type "vs target" (:target-type resolved)))) |
| 1008 | + (if (= tgt-eid report-eid) |
| 1009 | + (log/warn (str syntax ": " target-mid |
| 1010 | + " -- targets the same report (self-loop) -- ignored")) |
| 1011 | + (log/warn (str syntax ": type mismatch -- source") |
| 1012 | + source-type "vs target" (:target-type resolved))))) |
992 | 1013 | (apply-related-to! conn report-eid resolved email-eid from-addr failure-ctx))))) |
993 | 1014 |
|
994 | 1015 | (def ^:private unclose-relation-rows |
|
0 commit comments