Skip to content

Commit

Permalink
fix: makes diagnostic methods chainable again.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhartstonge committed Nov 28, 2024
1 parent e3cdbff commit a72c897
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions diag/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ type Builder struct {
e *Diagnostic
}

func (b *Builder) Fatal(summary, detail string) Diagnostics {
func (b *Builder) Fatal(summary, detail string) *Diagnostics {
return b.build(SeverityFatal, summary, detail)
}

func (b *Builder) Error(summary, detail string) Diagnostics {
func (b *Builder) Error(summary, detail string) *Diagnostics {
return b.build(SeverityError, summary, detail)
}

func (b *Builder) Warn(summary, detail string) Diagnostics {
func (b *Builder) Warn(summary, detail string) *Diagnostics {
return b.build(SeverityWarn, summary, detail)
}

func (b *Builder) Info(summary, detail string) Diagnostics {
func (b *Builder) Info(summary, detail string) *Diagnostics {
return b.build(SeverityInfo, summary, detail)
}

func (b *Builder) Debug(summary, detail string) Diagnostics {
func (b *Builder) Debug(summary, detail string) *Diagnostics {
return b.build(SeverityDebug, summary, detail)
}

func (b *Builder) Trace(summary, detail string) Diagnostics {
func (b *Builder) Trace(summary, detail string) *Diagnostics {
return b.build(SeverityTrace, summary, detail)
}

func (b *Builder) build(sev Severity, summary, detail string) Diagnostics {
func (b *Builder) build(sev Severity, summary, detail string) *Diagnostics {
diags, diag := b.d, b.e

diag.Severity = sev
Expand All @@ -41,5 +41,5 @@ func (b *Builder) build(sev Severity, summary, detail string) Diagnostics {

diags.Append(*diag)

return *diags
return diags
}
18 changes: 9 additions & 9 deletions diag/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (d *Diagnostics) Append(diags ...Diagnostic) {
}

// Merge appends the provided diags into the diagnostics.
func (d *Diagnostics) Merge(diags Diagnostics) {
func (d *Diagnostics) Merge(diags *Diagnostics) {
if diags.Len() == 0 {
// Nothing to append!
return
Expand Down Expand Up @@ -118,39 +118,39 @@ func (d *Diagnostics) builder(component Component, path string) *Builder {
}

// Fatals returns all diagnostic entries at SeverityFatal level.
func (d *Diagnostics) Fatals() Diagnostics {
func (d *Diagnostics) Fatals() *Diagnostics {
return d.getDiagsWithLevel(SeverityFatal)
}

// Errors returns all diagnostic entries at SeverityError level.
func (d *Diagnostics) Errors() Diagnostics {
func (d *Diagnostics) Errors() *Diagnostics {
return d.getDiagsWithLevel(SeverityError)
}

// Warnings returns all diagnostic entries at SeverityWarn level.
func (d *Diagnostics) Warnings() Diagnostics {
func (d *Diagnostics) Warnings() *Diagnostics {
return d.getDiagsWithLevel(SeverityWarn)
}

// Infos returns all diagnostic entries at SeverityInfo level.
func (d *Diagnostics) Infos() Diagnostics {
func (d *Diagnostics) Infos() *Diagnostics {
return d.getDiagsWithLevel(SeverityInfo)
}

// Debugs returns all diagnostic entries at SeverityDebug level.
func (d *Diagnostics) Debugs() Diagnostics {
func (d *Diagnostics) Debugs() *Diagnostics {
return d.getDiagsWithLevel(SeverityDebug)
}

// Traces returns all diagnostic entries at SeverityTrace level.
func (d *Diagnostics) Traces() Diagnostics {
func (d *Diagnostics) Traces() *Diagnostics {
return d.getDiagsWithLevel(SeverityTrace)
}

// getDiagsWithLevel returns an array of diagnostics that match the specified
// severity level.
func (d *Diagnostics) getDiagsWithLevel(sev Severity) Diagnostics {
var diags Diagnostics
func (d *Diagnostics) getDiagsWithLevel(sev Severity) *Diagnostics {
diags := &Diagnostics{}
for _, diag := range d.diags {
if diag.Severity != sev {
continue
Expand Down

0 comments on commit a72c897

Please sign in to comment.