resolveErrorMessageWithImportAttributes returns an updated error message with detailed information on the imported and overriden resource. example: "the component is invalid - , imported from Uri: http://example.com/devfile.yaml, in parent overrides from main devfile"
(validationErr error, attributes attributesAPI.Attributes)
| 229 | // example: |
| 230 | // "the component <compName> is invalid - <reason>, imported from Uri: http://example.com/devfile.yaml, in parent overrides from main devfile" |
| 231 | func resolveErrorMessageWithImportAttributes(validationErr error, attributes attributesAPI.Attributes) error { |
| 232 | var findKeyErr error |
| 233 | importReference := attributes.Get(ImportSourceAttribute, &findKeyErr) |
| 234 | |
| 235 | // overridden element must contain import resource information |
| 236 | // an overridden element can be either parentOverride or pluginOverride |
| 237 | // example: |
| 238 | // if an element is imported from another devfile, but contains no overrides - ImportSourceAttribute |
| 239 | // if an element is from parentOverride - ImportSourceAttribute + ParentOverrideAttribute |
| 240 | // if an element is from pluginOverride - ImportSourceAttribute + PluginOverrideAttribute |
| 241 | if findKeyErr == nil { |
| 242 | validationErr = fmt.Errorf("%s, imported from %s", validationErr.Error(), importReference) |
| 243 | parentOverrideReference := attributes.Get(ParentOverrideAttribute, &findKeyErr) |
| 244 | if findKeyErr == nil { |
| 245 | validationErr = fmt.Errorf("%s, in parent overrides from %s", validationErr.Error(), parentOverrideReference) |
| 246 | } else { |
| 247 | // reset findKeyErr to nil |
| 248 | findKeyErr = nil |
| 249 | pluginOverrideReference := attributes.Get(PluginOverrideAttribute, &findKeyErr) |
| 250 | if findKeyErr == nil { |
| 251 | validationErr = fmt.Errorf("%s, in plugin overrides from %s", validationErr.Error(), pluginOverrideReference) |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | return validationErr |
| 257 | } |
no test coverage detected