github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/grpcwrapper/rawydb/issues.go (about)

     1  package rawydb
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"strings"
     7  
     8  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Issue"
     9  
    10  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
    11  )
    12  
    13  type Issues []Issue
    14  
    15  func (issuesPointer *Issues) FromProto(p []*Ydb_Issue.IssueMessage) error {
    16  	*issuesPointer = make(Issues, len(p))
    17  	issues := *issuesPointer
    18  	for i := range issues {
    19  		if err := issues[i].FromProto(p[i]); err != nil {
    20  			return err
    21  		}
    22  	}
    23  
    24  	return nil
    25  }
    26  
    27  func (issuesPointer *Issues) String() string {
    28  	issues := *issuesPointer
    29  	issuesStrings := make([]string, len(issues))
    30  	for i := range issues {
    31  		issuesStrings[i] = issues[i].String()
    32  	}
    33  
    34  	return strings.Join(issuesStrings, ", ")
    35  }
    36  
    37  type Issue struct {
    38  	Code    uint32
    39  	Message string
    40  	Issues  Issues
    41  }
    42  
    43  func (issue *Issue) FromProto(p *Ydb_Issue.IssueMessage) error {
    44  	if p == nil {
    45  		return xerrors.WithStackTrace(errors.New("receive nil issue message pointer from protobuf"))
    46  	}
    47  	issue.Code = p.GetIssueCode()
    48  	issue.Message = p.GetMessage()
    49  
    50  	return issue.Issues.FromProto(p.GetIssues())
    51  }
    52  
    53  func (issue *Issue) String() string {
    54  	var innerIssues string
    55  	if len(issue.Issues) > 0 {
    56  		innerIssues = " (" + issue.Issues.String() + ")"
    57  	}
    58  
    59  	return fmt.Sprintf("message: %v, code: %v%v", issue.Message, issue.Code, innerIssues)
    60  }