github.com/opentofu/opentofu@v1.7.1/internal/tfdiags/diagnostic_base.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package tfdiags
     7  
     8  // diagnosticBase can be embedded in other diagnostic structs to get
     9  // default implementations of Severity and Description. This type also
    10  // has default implementations of Source and FromExpr that return no source
    11  // location or expression-related information, so embedders should generally
    12  // override those method to return more useful results where possible.
    13  type diagnosticBase struct {
    14  	severity Severity
    15  	summary  string
    16  	detail   string
    17  	address  string
    18  }
    19  
    20  func (d diagnosticBase) Severity() Severity {
    21  	return d.severity
    22  }
    23  
    24  func (d diagnosticBase) Description() Description {
    25  	return Description{
    26  		Summary: d.summary,
    27  		Detail:  d.detail,
    28  		Address: d.address,
    29  	}
    30  }
    31  
    32  func (d diagnosticBase) Source() Source {
    33  	return Source{}
    34  }
    35  
    36  func (d diagnosticBase) FromExpr() *FromExpr {
    37  	return nil
    38  }
    39  
    40  func (d diagnosticBase) ExtraInfo() interface{} {
    41  	return nil
    42  }