Skip to content

Commit 585c4db

Browse files
committed
Minor code cleanup; updated docs and ci settings
1 parent 5b714cb commit 585c4db

File tree

5 files changed

+59
-55
lines changed

5 files changed

+59
-55
lines changed

.travis.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
language: go
2-
2+
sudo: false
33
go:
4+
- 1.8
45
- 1.7.5
56
- 1.7.4
67
- 1.7.3
78
- 1.7.2
89
- 1.7.1
910
- 1.7
11+
- tip
1012
- 1.6.4
1113
- 1.6.3
1214
- 1.6.2
1315
- 1.6.1
1416
- 1.6
15-
- tip
1617
- 1.5.4
1718
- 1.5.3
1819
- 1.5.2
@@ -32,15 +33,19 @@ go:
3233
- 1.1.2
3334
- 1.1.1
3435
- 1.1
35-
- 1.0.3
36-
- 1.0.2
37-
- 1.0.1
38-
- 1
39-
36+
before_install:
37+
- go get github.com/mattn/goveralls
38+
script:
39+
- $HOME/gopath/bin/goveralls -service=travis-ci
4040
matrix:
4141
fast_finish: true
4242
allow_failures:
4343
- go: tip
44+
- go: 1.6.4
45+
- go: 1.6.3
46+
- go: 1.6.2
47+
- go: 1.6.1
48+
- go: 1.6
4449
- go: 1.5.4
4550
- go: 1.5.3
4651
- go: 1.5.2
@@ -60,7 +65,3 @@ matrix:
6065
- go: 1.1.2
6166
- go: 1.1.1
6267
- go: 1.1
63-
- go: 1.0.3
64-
- go: 1.0.2
65-
- go: 1.0.1
66-
- go: 1

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Extended `errors` package for Go (golang)
22

3-
This is a drop-in replacement for the standard [Go](http://golang.org) package with the same name, providing all the standard functionality as well as additional features.
3+
[![Release](https://img.shields.io/github/release/agext/errors.svg?style=flat)](https://github.com/agext/errors/releases/latest)
4+
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/agext/errors) 
5+
[![Build Status](https://travis-ci.org/agext/errors.svg?branch=master&style=flat)](https://travis-ci.org/agext/errors)
6+
[![Coverage Status](https://coveralls.io/repos/github/agext/errors/badge.svg?style=flat)](https://coveralls.io/github/agext/errors)
7+
[![Go Report Card](https://goreportcard.com/badge/github.com/agext/errors?style=flat)](https://goreportcard.com/report/github.com/agext/errors)
48

5-
## Maturity
9+
This is a drop-in replacement for the standard [Go](http://golang.org) package with the same name, providing all the standard functionality as well as additional features.
610

7-
[![Build Status](https://travis-ci.org/agext/errors.svg?branch=master)](https://travis-ci.org/agext/errors)
11+
## Project Status
812

9-
v1.0 Stable: Guaranteed no breaking changes to the API in future v1.x releases. No known bugs or performance issues. Probably safe to use in production, though provided on "AS IS" basis.
13+
v1.0.1 Stable: Guaranteed no breaking changes to the API in future v1.x releases. Probably safe to use in production, though provided on "AS IS" basis.
1014

1115
This package is being actively maintained. If you encounter any problems or have any suggestions for improvement, please [open an issue](https://github.com/agext/errors/issues). Pull requests are welcome.
1216

1317
## Overview
1418

15-
[![GoDoc](https://godoc.org/github.com/agext/errors?status.png)](https://godoc.org/github.com/agext/errors)
16-
1719
When you need to retain more information about an error message than a single string allows, just substitute this package for the one in the standard library.
1820

1921
The `New` function still accepts a single string as argument, so no code will be broken. Where you need to include additional information, you can provide it to `New` in a `Desc` structure instead of the string, or you can add it to the error message using one of its setter methods.

errors.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -101,60 +101,60 @@ func newFromE(desc *Desc) Error {
101101
// Log sends the error to the provided log, using the appropriate
102102
// logging function: FATAL conditions are logged using Fatal(), PANIC using
103103
// Panic(), and anything else using Print().
104-
func (this *errorMessage) Log(log Logger) Error {
105-
switch this.level {
104+
func (em *errorMessage) Log(log Logger) Error {
105+
switch em.level {
106106
case FATAL:
107-
log.Fatal(this)
107+
log.Fatal(em)
108108
case PANIC:
109-
log.Panic(this)
109+
log.Panic(em)
110110
default:
111-
log.Print(this)
111+
log.Print(em)
112112
}
113-
return this
113+
return em
114114
}
115115

116116
// Level returns the error level.
117-
func (this *errorMessage) Level() int8 {
118-
return this.level
117+
func (em *errorMessage) Level() int8 {
118+
return em.level
119119
}
120120

121121
// SetLevel sets the error level.
122-
func (this *errorMessage) SetLevel(l int8) Error {
122+
func (em *errorMessage) SetLevel(l int8) Error {
123123
if l >= minLevel && l <= maxLevel {
124-
this.level = l
124+
em.level = l
125125
}
126-
return this
126+
return em
127127
}
128128

129129
// Code returns the error code.
130-
func (this *errorMessage) Code() int {
131-
return this.code
130+
func (em *errorMessage) Code() int {
131+
return em.code
132132
}
133133

134134
// SetCode sets the error code.
135-
func (this *errorMessage) SetCode(c int) Error {
136-
this.code = c
137-
return this
135+
func (em *errorMessage) SetCode(c int) Error {
136+
em.code = c
137+
return em
138138
}
139139

140140
// Text returns the error text.
141-
func (this *errorMessage) Text() string {
142-
return this.text
141+
func (em *errorMessage) Text() string {
142+
return em.text
143143
}
144144

145145
// SetText sets the error text.
146-
func (this *errorMessage) SetText(t string) Error {
147-
this.text = t
148-
return this
146+
func (em *errorMessage) SetText(t string) Error {
147+
em.text = t
148+
return em
149149
}
150150

151151
// Info returns the error info.
152-
func (this *errorMessage) Info() []string {
153-
return this.info
152+
func (em *errorMessage) Info() []string {
153+
return em.info
154154
}
155155

156156
// addInfo adds (more) error info.
157-
func (this *errorMessage) addInfo(calldepth int, s ...string) Error {
157+
func (em *errorMessage) addInfo(calldepth int, s ...string) Error {
158158
for i, line := range s {
159159
if line == "debug.stack" {
160160
calldepth *= 2
@@ -180,20 +180,20 @@ func (this *errorMessage) addInfo(calldepth int, s ...string) Error {
180180
break
181181
}
182182
}
183-
this.info = append(this.info, s...)
184-
return this
183+
em.info = append(em.info, s...)
184+
return em
185185
}
186186

187187
// AddInfo adds (more) error info.
188-
func (this *errorMessage) AddInfo(s ...string) Error {
189-
return this.addInfo(2, s...)
188+
func (em *errorMessage) AddInfo(s ...string) Error {
189+
return em.addInfo(2, s...)
190190
}
191191

192192
// Error returns a text containing the error message and code;
193193
// it is useful for satisfying the `error` interface.
194-
func (this *errorMessage) Error() string {
195-
if this.code != 0 {
196-
return this.text + fmt.Sprintf(" (code: 0x%04x)", this.code)
194+
func (em *errorMessage) Error() string {
195+
if em.code != 0 {
196+
return em.text + fmt.Sprintf(" (code: 0x%04x)", em.code)
197197
}
198-
return this.text
198+
return em.text
199199
}

errors_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ type mockLogger struct {
2424
log string
2525
}
2626

27-
func (this *mockLogger) Print(s ...interface{}) {
28-
this.log += fmt.Sprintln(s...)
27+
func (ml *mockLogger) Print(s ...interface{}) {
28+
ml.log += fmt.Sprintln(s...)
2929
}
30-
func (this *mockLogger) Fatal(s ...interface{}) {
31-
this.log += "[FATAL] " + fmt.Sprintln(s...)
30+
func (ml *mockLogger) Fatal(s ...interface{}) {
31+
ml.log += "[FATAL] " + fmt.Sprintln(s...)
3232
}
33-
func (this *mockLogger) Panic(s ...interface{}) {
34-
this.log += "[PANIC] " + fmt.Sprintln(s...)
33+
func (ml *mockLogger) Panic(s ...interface{}) {
34+
ml.log += "[PANIC] " + fmt.Sprintln(s...)
3535
}
3636

3737
func TestNew(t *testing.T) {

helpers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func levelName(l int8) string {
4444
return "?"
4545
}
4646

47+
// Logger defines the interface expected by the Log method of Error
4748
type Logger interface {
4849
Fatal(...interface{})
4950
Panic(...interface{})

0 commit comments

Comments
 (0)