| 168 | } |
| 169 | |
| 170 | func GetCompatibleSource[T any](resourceMgr SourceProvider, sourceName, toolName, toolType string) (T, error) { |
| 171 | var zero T |
| 172 | s, ok := resourceMgr.GetSource(sourceName) |
| 173 | if !ok { |
| 174 | return zero, fmt.Errorf("unable to retrieve source %q for tool %q", sourceName, toolName) |
| 175 | } |
| 176 | source, ok := s.(T) |
| 177 | if !ok { |
| 178 | return zero, fmt.Errorf("invalid source for %q tool: source %q is not a compatible type", toolType, sourceName) |
| 179 | } |
| 180 | return source, nil |
| 181 | } |
| 182 | |
| 183 | // GetCompatibleSourceFromMap looks up a source by name from a sources map and |
| 184 | // asserts it to the requested type. It mirrors GetCompatibleSource for callers |