-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package diag | ||
|
||
import "fmt" | ||
|
||
// FromErr will convert an error into a Diagnostics. This returns Diagnostics | ||
// as the most common use case in Go will be handling a single error | ||
// returned from a function. | ||
// | ||
// if err != nil { | ||
// return diag.FromErr(err) | ||
// } | ||
func FromErr(err error) Diagnostics { | ||
return Diagnostics{ | ||
Diagnostic{ | ||
Severity: Error, | ||
Summary: err.Error(), | ||
}, | ||
} | ||
} | ||
|
||
// Errorf creates a Diagnostics with a single Error level Diagnostic entry. | ||
// The summary is populated by performing a fmt.Sprintf with the supplied | ||
// values. This returns a single error in a Diagnostics as errors typically | ||
// do not occur in multiples as warnings may. | ||
// | ||
// if unexpectedCondition { | ||
// return diag.Errorf("unexpected: %s", someValue) | ||
// } | ||
func Errorf(format string, a ...interface{}) Diagnostics { | ||
return Diagnostics{ | ||
Diagnostic{ | ||
Severity: Error, | ||
Summary: fmt.Sprintf(format, a...), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters