Skip to content

Commit 338a228

Browse files
authored
Update README.md
1 parent 04843f9 commit 338a228

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ return errors.New("now this is unfortunate")
1010
Then being handled with a no-brainer:
1111
```go
1212
if err != nil {
13-
return nil, err
13+
return err
1414
}
1515
```
1616

@@ -27,14 +27,14 @@ It doesn't take long to find out that this is not often enough. There's little f
2727
> Error: wrong argument value
2828
2929
An *errorx* library makes an approach to create a toolset that would help remedy this issue with these considerations in mind:
30-
* No extra care should be required for an error to have all the required debug information; it is the opposite that may constitute a special case
30+
* No extra care should be required for an error to have all the necessary debug information; it is the opposite that may constitute a special case
3131
* There must be a way to distinguish one kind of error from another, as they may imply or require a different handling in user code
3232
* Errors must be composable, and patterns like ```if err == io.EOF``` defeat that purpose, so they should be avoided
3333
* Some context information may be added to the error along the way, and there must be a way to do so without altering the semantics of the error
3434
* It must be easy to create an error, add some context to it, check for it
3535
* A kind of error that requires a special treatment by the caller *is* a part of a public API; an excessive amount of such kinds is a code smell
3636

37-
As a result, the goal of the library is to provide a brief, expressive syntax for a conventional error handling and to discourage usage patterns that bring less value than harm.
37+
As a result, the goal of the library is to provide a brief, expressive syntax for a conventional error handling and to discourage usage patterns that bring more harm than they're worth.
3838

3939
Error-related, negative codepath is typically less well tested, though of, and may confuse the reader more than its positive counterpart. Therefore, an error system could do well without too much of a flexibility and unpredictability
4040

@@ -43,11 +43,11 @@ Error-related, negative codepath is typically less well tested, though of, and m
4343
With *errorx*, the pattern above looks like this:
4444

4545
```go
46-
return nil, errorx.IllegalState.New("unfortunate")
46+
return errorx.IllegalState.New("unfortunate")
4747
```
4848
```go
4949
if err != nil {
50-
return nil, errorx.Decorate(err, "this could be so much better")
50+
return errorx.Decorate(err, "this could be so much better")
5151
}
5252
```
5353
```go
@@ -74,6 +74,7 @@ And this, frankly, may be quite enough. With a set of standard error types provi
7474

7575
If an error requires special treatment, it may be done like this:
7676
```go
77+
// MyError = MyNamespace.NewType("my_error")
7778
if errorx.IsOfType(err, MyError) {
7879
// handle
7980
}
@@ -83,6 +84,7 @@ Note that it is never a good idea to inspect a message of an error. Type check,
8384

8485
An alternative is a mechanisms called **traits**:
8586
```go
87+
// thie first parameter is a name of new error type, the second is a reference to existing declared trait
8688
TimeoutElapsed = CommonErrors.NewType("timeout", Timeout())
8789
```
8890

@@ -99,7 +101,7 @@ Note that here a check is made against a trait, not a type, so any type with the
99101

100102
The example above introduced ```errorx.Decorate()```, a syntax used to add message as an error is passed along. This mechanism is highly non-intrusive: any properties an original error possessed, a result of a ```Decorate()``` will possess, too.
101103

102-
Sometimes, though, it is not the desired effect. A possibility to make a type check as a double edged one, and should be restricted as often as it is allowed. The bad way to do so would be to create a new error and to pass an ```Error()``` output as a message. Among other possible issues, this would either lose or duplicate the stack trace information.
104+
Sometimes, though, it is not the desired effect. A possibility to make a type check is a double edged one, and should be restricted as often as it is allowed. The bad way to do so would be to create a new error and to pass an ```Error()``` output as a message. Among other possible issues, this would either lose or duplicate the stack trace information.
103105

104106
A better alternative is:
105107
```go
@@ -114,7 +116,7 @@ See ```WrapMany()``` and ```DecorateMany()``` for more sophisticated cases.
114116

115117
As an essential part of debug information, stack traces are included in all *errorx* errors by default.
116118

117-
When an error is passed along, the original stack trace is simply retained, as this typically takes place along the lines if the same frames that were originally captured. When an error is received from another goroutine, use this to add frames that would otherwise be missing:
119+
When an error is passed along, the original stack trace is simply retained, as this typically takes place along the lines of the same frames that were originally captured. When an error is received from another goroutine, use this to add frames that would otherwise be missing:
118120

119121
```go
120122
return errorx.EnhanceStackTrace(<-errorChan, "task failed")

0 commit comments

Comments
 (0)