Skip to content

Commit 122f853

Browse files
authored
Merge pull request #483 from rodoufu/improveErrors
Improve error information
2 parents efd43e2 + 9a59f46 commit 122f853

File tree

13 files changed

+81
-44
lines changed

13 files changed

+81
-44
lines changed

application.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
package quickfix
22

3-
//The Application interface should be implemented by FIX Applications.
3+
//Application interface should be implemented by FIX Applications.
44
//This is the primary interface for processing messages from a FIX Session.
55
type Application interface {
6-
//Notification of a session begin created.
6+
//OnCreate notification of a session begin created.
77
OnCreate(sessionID SessionID)
88

9-
//Notification of a session successfully logging on.
9+
//OnLogon notification of a session successfully logging on.
1010
OnLogon(sessionID SessionID)
1111

12-
//Notification of a session logging off or disconnecting.
12+
//OnLogout notification of a session logging off or disconnecting.
1313
OnLogout(sessionID SessionID)
1414

15-
//Notification of admin message being sent to target.
15+
//ToAdmin notification of admin message being sent to target.
1616
ToAdmin(message *Message, sessionID SessionID)
1717

18-
//Notification of app message being sent to target.
18+
//ToApp notification of app message being sent to target.
1919
ToApp(message *Message, sessionID SessionID) error
2020

21-
//Notification of admin message being received from target.
21+
//FromAdmin notification of admin message being received from target.
2222
FromAdmin(message *Message, sessionID SessionID) MessageRejectError
2323

24-
//Notification of app message being received from target.
24+
//FromApp notification of app message being received from target.
2525
FromApp(message *Message, sessionID SessionID) MessageRejectError
2626
}

datadictionary/datadictionary.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"encoding/xml"
66
"io"
77
"os"
8+
9+
"github.com/pkg/errors"
810
)
911

1012
//DataDictionary models FIX messages, components, and fields.
@@ -297,24 +299,25 @@ func NewMessageDef(name, msgType string, parts []MessagePart) *MessageDef {
297299
return &msg
298300
}
299301

300-
//Parse loads and and build a datadictionary instance from an xml file.
302+
//Parse loads and build a datadictionary instance from an xml file.
301303
func Parse(path string) (*DataDictionary, error) {
302304
var xmlFile *os.File
303-
xmlFile, err := os.Open(path)
305+
var err error
306+
xmlFile, err = os.Open(path)
304307
if err != nil {
305-
return nil, err
308+
return nil, errors.Wrapf(err, "problem opening file: %v", path)
306309
}
307310
defer xmlFile.Close()
308311

309312
return ParseSrc(xmlFile)
310313
}
311314

312-
//ParseSrc loads and and build a datadictionary instance from an xml source.
315+
//ParseSrc loads and build a datadictionary instance from an xml source.
313316
func ParseSrc(xmlSrc io.Reader) (*DataDictionary, error) {
314317
doc := new(XMLDoc)
315318
decoder := xml.NewDecoder(xmlSrc)
316319
if err := decoder.Decode(doc); err != nil {
317-
return nil, err
320+
return nil, errors.Wrapf(err, "problem parsing XML file")
318321
}
319322

320323
b := new(builder)

field.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package quickfix
22

33
//FieldValueWriter is an interface for writing field values
44
type FieldValueWriter interface {
5-
//Writes out the contents of the FieldValue to a []byte
5+
//Write writes out the contents of the FieldValue to a []byte
66
Write() []byte
77
}
88

99
//FieldValueReader is an interface for reading field values
1010
type FieldValueReader interface {
11-
//Reads the contents of the []byte into FieldValue. Returns an error if there are issues in the data processing
11+
//Read reads the contents of the []byte into FieldValue.
12+
//Returns an error if there are issues in the data processing
1213
Read([]byte) error
1314
}
1415

filestore.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/pkg/errors"
13+
1314
"github.com/quickfixgo/quickfix/config"
1415
)
1516

@@ -275,11 +276,11 @@ func (store *fileStore) CreationTime() time.Time {
275276
}
276277

277278
func (store *fileStore) SaveMessage(seqNum int, msg []byte) error {
278-
offset, err := store.bodyFile.Seek(0, os.SEEK_END)
279+
offset, err := store.bodyFile.Seek(0, io.SeekEnd)
279280
if err != nil {
280281
return fmt.Errorf("unable to seek to end of file: %s: %s", store.bodyFname, err.Error())
281282
}
282-
if _, err := store.headerFile.Seek(0, os.SEEK_END); err != nil {
283+
if _, err := store.headerFile.Seek(0, io.SeekEnd); err != nil {
283284
return fmt.Errorf("unable to seek to end of file: %s: %s", store.headerFname, err.Error())
284285
}
285286
if _, err := fmt.Fprintf(store.headerFile, "%d,%d,%d\n", seqNum, offset, len(msg)); err != nil {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ require (
88
github.com/kr/text v0.2.0 // indirect
99
github.com/mattn/go-sqlite3 v1.14.7
1010
github.com/pkg/errors v0.9.1
11-
github.com/shopspring/decimal v1.2.0
11+
github.com/shopspring/decimal v1.3.1
1212
github.com/stretchr/objx v0.3.0 // indirect
1313
github.com/stretchr/testify v1.7.0
14-
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
14+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
1515
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
1616
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
1717
)

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
2020
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2121
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
2222
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
23+
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
24+
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
2325
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2426
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
2527
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
@@ -28,10 +30,16 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
2830
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
2931
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
3032
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
33+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
34+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
3135
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3236
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
37+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
38+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3339
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
40+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
3441
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
42+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
3543
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
3644
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3745
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=

internal/time_range.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package internal
22

33
import (
4-
"errors"
54
"time"
5+
6+
"github.com/pkg/errors"
67
)
78

89
//TimeOfDay represents the time of day
@@ -13,8 +14,6 @@ type TimeOfDay struct {
1314

1415
const shortForm = "15:04:05"
1516

16-
var errParseTime = errors.New("Time must be in the format HH:MM:SS")
17-
1817
//NewTimeOfDay returns a newly initialized TimeOfDay
1918
func NewTimeOfDay(hour, minute, second int) TimeOfDay {
2019
d := time.Duration(second)*time.Second +
@@ -28,7 +27,7 @@ func NewTimeOfDay(hour, minute, second int) TimeOfDay {
2827
func ParseTimeOfDay(str string) (TimeOfDay, error) {
2928
t, err := time.Parse(shortForm, str)
3029
if err != nil {
31-
return TimeOfDay{}, errParseTime
30+
return TimeOfDay{}, errors.Wrap(err, "time must be in the format HH:MM:SS")
3231
}
3332

3433
return NewTimeOfDay(t.Clock()), nil

log.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ package quickfix
22

33
//Log is a generic interface for logging FIX messages and events.
44
type Log interface {
5-
//log incoming fix message
5+
//OnIncoming log incoming fix message
66
OnIncoming([]byte)
77

8-
//log outgoing fix message
8+
//OnOutgoing log outgoing fix message
99
OnOutgoing([]byte)
1010

11-
//log fix event
11+
//OnEvent log fix event
1212
OnEvent(string)
1313

14-
//log fix event according to format specifier
14+
//OnEventf log fix event according to format specifier
1515
OnEventf(string, ...interface{})
1616
}
1717

1818
//The LogFactory interface creates global and session specific Log instances
1919
type LogFactory interface {
20-
//global log
20+
//Create global log
2121
Create() (Log, error)
2222

23-
//session specific log
23+
//CreateSessionLog session specific log
2424
CreateSessionLog(sessionID SessionID) (Log, error)
2525
}

repeating_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type GroupItem interface {
1111
//Tag returns the tag identifying this GroupItem
1212
Tag() Tag
1313

14-
//Parameter to Read is tagValues. For most fields, only the first tagValue will be required.
14+
//Read Parameter to Read is tagValues. For most fields, only the first tagValue will be required.
1515
//The length of the slice extends from the tagValue mapped to the field to be read through the
1616
//following fields. This can be useful for GroupItems made up of repeating groups.
1717
//

session_factory.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package quickfix
22

33
import (
4-
"errors"
54
"net"
65
"strconv"
76
"time"
87

8+
"github.com/pkg/errors"
9+
910
"github.com/quickfixgo/quickfix/config"
1011
"github.com/quickfixgo/quickfix/datadictionary"
1112
"github.com/quickfixgo/quickfix/internal"
@@ -103,10 +104,18 @@ func (f sessionFactory) newSession(
103104
}
104105

105106
if s.transportDataDictionary, err = datadictionary.Parse(transportDataDictionaryPath); err != nil {
107+
err = errors.Wrapf(
108+
err, "problem parsing XML datadictionary path '%v' for setting '%v",
109+
settings.settings[config.TransportDataDictionary], config.TransportDataDictionary,
110+
)
106111
return
107112
}
108113

109114
if s.appDataDictionary, err = datadictionary.Parse(appDataDictionaryPath); err != nil {
115+
err = errors.Wrapf(
116+
err, "problem parsing XML datadictionary path '%v' for setting '%v",
117+
settings.settings[config.AppDataDictionary], config.AppDataDictionary,
118+
)
110119
return
111120
}
112121

@@ -119,6 +128,10 @@ func (f sessionFactory) newSession(
119128
}
120129

121130
if s.appDataDictionary, err = datadictionary.Parse(dataDictionaryPath); err != nil {
131+
err = errors.Wrapf(
132+
err, "problem parsing XML datadictionary path '%v' for setting '%v",
133+
settings.settings[config.DataDictionary], config.DataDictionary,
134+
)
122135
return
123136
}
124137

@@ -198,10 +211,18 @@ func (f sessionFactory) newSession(
198211

199212
var start, end internal.TimeOfDay
200213
if start, err = internal.ParseTimeOfDay(startTimeStr); err != nil {
214+
err = errors.Wrapf(
215+
err, "problem parsing time of day '%v' for setting '%v",
216+
settings.settings[config.StartTime], config.StartTime,
217+
)
201218
return
202219
}
203220

204221
if end, err = internal.ParseTimeOfDay(endTimeStr); err != nil {
222+
err = errors.Wrapf(
223+
err, "problem parsing time of day '%v' for setting '%v",
224+
settings.settings[config.EndTime], config.EndTime,
225+
)
205226
return
206227
}
207228

@@ -214,6 +235,10 @@ func (f sessionFactory) newSession(
214235

215236
loc, err = time.LoadLocation(locStr)
216237
if err != nil {
238+
err = errors.Wrapf(
239+
err, "problem parsing time zone '%v' for setting '%v",
240+
settings.settings[config.TimeZone], config.TimeZone,
241+
)
217242
return
218243
}
219244
}
@@ -404,7 +429,7 @@ func (f sessionFactory) buildHeartBtIntSettings(session *session, settings *Sess
404429
return
405430
}
406431
}
407-
432+
408433
if session.HeartBtIntOverride || mustProvide {
409434
var heartBtInt int
410435
if heartBtInt, err = settings.IntSetting(config.HeartBtInt); err != nil {

0 commit comments

Comments
 (0)