ResolveFieldByID finds the project field whose node ID matches id, validating it against the fields returned with the project so an unknown ID fails with a candidate-carrying *FieldIDNotFoundError instead of silently rendering an empty column. Node IDs are matched exactly (they are case-sensitive).
(fields []ProjectField, id string)
| 95 | // candidate-carrying *FieldIDNotFoundError instead of silently rendering an |
| 96 | // empty column. Node IDs are matched exactly (they are case-sensitive). |
| 97 | func ResolveFieldByID(fields []ProjectField, id string) (ProjectField, error) { |
| 98 | for _, f := range fields { |
| 99 | if f.ID() == id { |
| 100 | return f, nil |
| 101 | } |
| 102 | } |
| 103 | candidates := make([]string, 0, len(fields)) |
| 104 | for _, f := range fields { |
| 105 | candidates = append(candidates, fmt.Sprintf("%s (%s)", f.Name(), f.ID())) |
| 106 | } |
| 107 | sort.Strings(candidates) |
| 108 | return ProjectField{}, &FieldIDNotFoundError{ID: id, Candidates: candidates} |
| 109 | } |