Helper for determining if a Diagnostics contains errors

Checking if it's non-nil, as we would for Go errors, doesn't work here
because there may be warnings.
This commit is contained in:
Martin Atkins 2017-05-16 07:58:34 -07:00
parent 8dfc3c4bbe
commit b5a78fd826

View File

@ -84,3 +84,14 @@ func (d Diagnostics) Append(diag *Diagnostic) Diagnostics {
func (d Diagnostics) Extend(diags Diagnostics) Diagnostics { func (d Diagnostics) Extend(diags Diagnostics) Diagnostics {
return append(d, diags...) return append(d, diags...)
} }
// HasErrors returns true if the receiver contains any diagnostics of
// severity DiagError.
func (d Diagnostics) HasErrors() bool {
for _, diag := range d {
if diag.Severity == DiagError {
return true
}
}
return false
}