func NewErrorReport()

in tf/utils.go [327:365]


func NewErrorReport(applyErr error, logs []paltypes.RequestTrace) types.ErrorReport {
	out := types.ErrorReport{
		Errors: make([]types.Error, 0),
		Logs:   logs,
	}
	if applyErr == nil {
		return out
	}
	var res []string
	if strings.Contains(applyErr.Error(), "Error: Failed to create/update resource") {
		res = strings.Split(applyErr.Error(), "Error: Failed to create/update resource")
	} else {
		res = strings.Split(applyErr.Error(), "Error: creating/updating")
	}
	for _, e := range res {
		var id, apiVersion, label string
		errorMessage := e
		if lastIndex := strings.LastIndex(e, "------"); lastIndex != -1 {
			errorMessage = errorMessage[0:lastIndex]
		}
		if matches := regexp.MustCompile(`ResourceId\s+\\?"([^\\]+)\\?"\s+/\s+Api Version \\?"([^\\]+)\\?"\)`).FindAllStringSubmatch(e, -1); len(matches) == 1 {
			id = matches[0][1]
			apiVersion = matches[0][2]
		}
		if matches := regexp.MustCompile(`resource "azapi_.+" "(.+)"`).FindAllStringSubmatch(e, -1); len(matches) != 0 {
			label = matches[0][1]
		}
		if len(label) == 0 {
			continue
		}
		out.Errors = append(out.Errors, types.Error{
			Id:      id,
			Type:    fmt.Sprintf("%s@%s", utils.ResourceTypeOfResourceId(id), apiVersion),
			Label:   label,
			Message: errorMessage,
		})
	}
	return out
}