Skip to content

Commit f017cc0

Browse files
committed
docs: update code snippet to match actual implementation
Address Copilot review comment: The documentation now shows the exact code from internal/core/run.go instead of pseudocode, including the proper error handling and variable names (r.relManager, url, errors.*)
1 parent 71c2127 commit f017cc0

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

docs/TROUBLESHOOTING_DOCX_VALIDATION.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,33 @@ This caused:
9191

9292
### Solution
9393

94-
**File:** `internal/core/run.go` (lines 238-257)
94+
**File:** `internal/core/run.go` - `AddField()` method
9595

9696
Before generating a new relationship, check if a preserved one already exists:
9797

9898
```go
9999
// Check if this hyperlink already has a relationship ID (preserved from read)
100+
// If so, skip creating a new one to preserve original document references
100101
existingRelID, hasExistingRelID := accessor.GetProperty("relationshipID")
101102
if hasExistingRelID && existingRelID != "" {
102103
// Already has a relationship ID, skip creating new one
103-
// The preserved ID will be used during serialization
104104
} else {
105105
// No existing relationship ID, create a new one
106-
if relMgr := accessor.RelationshipManager(); relMgr != nil {
107-
relID, err := relMgr.AddHyperlink(link)
108-
if err != nil {
109-
return fmt.Errorf("failed to add hyperlink relationship: %w", err)
110-
}
111-
accessor.SetProperty("relationshipID", relID)
106+
if r.relManager == nil {
107+
return errors.InvalidState("Run.AddField", "hyperlink relationship manager not initialized")
108+
}
109+
110+
url, ok := accessor.GetProperty("url")
111+
if !ok || url == "" {
112+
return errors.InvalidArgument("Run.AddField", "url", url, "hyperlink URL cannot be empty")
112113
}
114+
115+
relID, err := r.relManager.AddHyperlink(url)
116+
if err != nil {
117+
return errors.Wrap(err, "Run.AddField")
118+
}
119+
120+
accessor.SetProperty("relationshipID", relID)
113121
}
114122
```
115123

0 commit comments

Comments
 (0)