diff --git a/application.go b/application.go index 09b3b49a3..e91ab1021 100644 --- a/application.go +++ b/application.go @@ -1,26 +1,26 @@ package quickfix -//The Application interface should be implemented by FIX Applications. +//Application interface should be implemented by FIX Applications. //This is the primary interface for processing messages from a FIX Session. type Application interface { - //Notification of a session begin created. + //OnCreate notification of a session begin created. OnCreate(sessionID SessionID) - //Notification of a session successfully logging on. + //OnLogon notification of a session successfully logging on. OnLogon(sessionID SessionID) - //Notification of a session logging off or disconnecting. + //OnLogout notification of a session logging off or disconnecting. OnLogout(sessionID SessionID) - //Notification of admin message being sent to target. + //ToAdmin notification of admin message being sent to target. ToAdmin(message *Message, sessionID SessionID) - //Notification of app message being sent to target. + //ToApp notification of app message being sent to target. ToApp(message *Message, sessionID SessionID) error - //Notification of admin message being received from target. + //FromAdmin notification of admin message being received from target. FromAdmin(message *Message, sessionID SessionID) MessageRejectError - //Notification of app message being received from target. + //FromApp notification of app message being received from target. FromApp(message *Message, sessionID SessionID) MessageRejectError } diff --git a/datadictionary/datadictionary.go b/datadictionary/datadictionary.go index 49ba19015..ea93f6b25 100644 --- a/datadictionary/datadictionary.go +++ b/datadictionary/datadictionary.go @@ -5,6 +5,8 @@ import ( "encoding/xml" "io" "os" + + "github.com/pkg/errors" ) //DataDictionary models FIX messages, components, and fields. @@ -297,24 +299,25 @@ func NewMessageDef(name, msgType string, parts []MessagePart) *MessageDef { return &msg } -//Parse loads and and build a datadictionary instance from an xml file. +//Parse loads and build a datadictionary instance from an xml file. func Parse(path string) (*DataDictionary, error) { var xmlFile *os.File - xmlFile, err := os.Open(path) + var err error + xmlFile, err = os.Open(path) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "problem opening file: %v", path) } defer xmlFile.Close() return ParseSrc(xmlFile) } -//ParseSrc loads and and build a datadictionary instance from an xml source. +//ParseSrc loads and build a datadictionary instance from an xml source. func ParseSrc(xmlSrc io.Reader) (*DataDictionary, error) { doc := new(XMLDoc) decoder := xml.NewDecoder(xmlSrc) if err := decoder.Decode(doc); err != nil { - return nil, err + return nil, errors.Wrapf(err, "problem parsing XML file") } b := new(builder) diff --git a/field.go b/field.go index 044e31418..43b9e4d86 100644 --- a/field.go +++ b/field.go @@ -2,13 +2,14 @@ package quickfix //FieldValueWriter is an interface for writing field values type FieldValueWriter interface { - //Writes out the contents of the FieldValue to a []byte + //Write writes out the contents of the FieldValue to a []byte Write() []byte } //FieldValueReader is an interface for reading field values type FieldValueReader interface { - //Reads the contents of the []byte into FieldValue. Returns an error if there are issues in the data processing + //Read reads the contents of the []byte into FieldValue. + //Returns an error if there are issues in the data processing Read([]byte) error } diff --git a/filestore.go b/filestore.go index 6d010f897..976273754 100644 --- a/filestore.go +++ b/filestore.go @@ -10,6 +10,7 @@ import ( "time" "github.com/pkg/errors" + "github.com/quickfixgo/quickfix/config" ) @@ -275,11 +276,11 @@ func (store *fileStore) CreationTime() time.Time { } func (store *fileStore) SaveMessage(seqNum int, msg []byte) error { - offset, err := store.bodyFile.Seek(0, os.SEEK_END) + offset, err := store.bodyFile.Seek(0, io.SeekEnd) if err != nil { return fmt.Errorf("unable to seek to end of file: %s: %s", store.bodyFname, err.Error()) } - if _, err := store.headerFile.Seek(0, os.SEEK_END); err != nil { + if _, err := store.headerFile.Seek(0, io.SeekEnd); err != nil { return fmt.Errorf("unable to seek to end of file: %s: %s", store.headerFname, err.Error()) } if _, err := fmt.Fprintf(store.headerFile, "%d,%d,%d\n", seqNum, offset, len(msg)); err != nil { diff --git a/go.mod b/go.mod index bb753f61f..8de42b87a 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/kr/text v0.2.0 // indirect github.com/mattn/go-sqlite3 v1.14.7 github.com/pkg/errors v0.9.1 - github.com/shopspring/decimal v1.2.0 + github.com/shopspring/decimal v1.3.1 github.com/stretchr/objx v0.3.0 // indirect github.com/stretchr/testify v1.7.0 - golang.org/x/net v0.0.0-20210614182718-04defd469f4e + golang.org/x/net v0.0.0-20220225172249-27dd8689420f gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 277635b4b..4d56b87d5 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= +github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As= github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= @@ -28,10 +30,16 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q= golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/internal/time_range.go b/internal/time_range.go index b7fa4569b..e69f2fd21 100644 --- a/internal/time_range.go +++ b/internal/time_range.go @@ -1,8 +1,9 @@ package internal import ( - "errors" "time" + + "github.com/pkg/errors" ) //TimeOfDay represents the time of day @@ -13,8 +14,6 @@ type TimeOfDay struct { const shortForm = "15:04:05" -var errParseTime = errors.New("Time must be in the format HH:MM:SS") - //NewTimeOfDay returns a newly initialized TimeOfDay func NewTimeOfDay(hour, minute, second int) TimeOfDay { d := time.Duration(second)*time.Second + @@ -28,7 +27,7 @@ func NewTimeOfDay(hour, minute, second int) TimeOfDay { func ParseTimeOfDay(str string) (TimeOfDay, error) { t, err := time.Parse(shortForm, str) if err != nil { - return TimeOfDay{}, errParseTime + return TimeOfDay{}, errors.Wrap(err, "time must be in the format HH:MM:SS") } return NewTimeOfDay(t.Clock()), nil diff --git a/log.go b/log.go index 6527e92dc..6b1fa04bb 100644 --- a/log.go +++ b/log.go @@ -2,24 +2,24 @@ package quickfix //Log is a generic interface for logging FIX messages and events. type Log interface { - //log incoming fix message + //OnIncoming log incoming fix message OnIncoming([]byte) - //log outgoing fix message + //OnOutgoing log outgoing fix message OnOutgoing([]byte) - //log fix event + //OnEvent log fix event OnEvent(string) - //log fix event according to format specifier + //OnEventf log fix event according to format specifier OnEventf(string, ...interface{}) } //The LogFactory interface creates global and session specific Log instances type LogFactory interface { - //global log + //Create global log Create() (Log, error) - //session specific log + //CreateSessionLog session specific log CreateSessionLog(sessionID SessionID) (Log, error) } diff --git a/repeating_group.go b/repeating_group.go index 811379c37..183047c1f 100644 --- a/repeating_group.go +++ b/repeating_group.go @@ -11,7 +11,7 @@ type GroupItem interface { //Tag returns the tag identifying this GroupItem Tag() Tag - //Parameter to Read is tagValues. For most fields, only the first tagValue will be required. + //Read Parameter to Read is tagValues. For most fields, only the first tagValue will be required. //The length of the slice extends from the tagValue mapped to the field to be read through the //following fields. This can be useful for GroupItems made up of repeating groups. // diff --git a/session_factory.go b/session_factory.go index d119274cc..8fc42d3c0 100644 --- a/session_factory.go +++ b/session_factory.go @@ -1,11 +1,12 @@ package quickfix import ( - "errors" "net" "strconv" "time" + "github.com/pkg/errors" + "github.com/quickfixgo/quickfix/config" "github.com/quickfixgo/quickfix/datadictionary" "github.com/quickfixgo/quickfix/internal" @@ -103,10 +104,18 @@ func (f sessionFactory) newSession( } if s.transportDataDictionary, err = datadictionary.Parse(transportDataDictionaryPath); err != nil { + err = errors.Wrapf( + err, "problem parsing XML datadictionary path '%v' for setting '%v", + settings.settings[config.TransportDataDictionary], config.TransportDataDictionary, + ) return } if s.appDataDictionary, err = datadictionary.Parse(appDataDictionaryPath); err != nil { + err = errors.Wrapf( + err, "problem parsing XML datadictionary path '%v' for setting '%v", + settings.settings[config.AppDataDictionary], config.AppDataDictionary, + ) return } @@ -119,6 +128,10 @@ func (f sessionFactory) newSession( } if s.appDataDictionary, err = datadictionary.Parse(dataDictionaryPath); err != nil { + err = errors.Wrapf( + err, "problem parsing XML datadictionary path '%v' for setting '%v", + settings.settings[config.DataDictionary], config.DataDictionary, + ) return } @@ -198,10 +211,18 @@ func (f sessionFactory) newSession( var start, end internal.TimeOfDay if start, err = internal.ParseTimeOfDay(startTimeStr); err != nil { + err = errors.Wrapf( + err, "problem parsing time of day '%v' for setting '%v", + settings.settings[config.StartTime], config.StartTime, + ) return } if end, err = internal.ParseTimeOfDay(endTimeStr); err != nil { + err = errors.Wrapf( + err, "problem parsing time of day '%v' for setting '%v", + settings.settings[config.EndTime], config.EndTime, + ) return } @@ -214,6 +235,10 @@ func (f sessionFactory) newSession( loc, err = time.LoadLocation(locStr) if err != nil { + err = errors.Wrapf( + err, "problem parsing time zone '%v' for setting '%v", + settings.settings[config.TimeZone], config.TimeZone, + ) return } } @@ -404,7 +429,7 @@ func (f sessionFactory) buildHeartBtIntSettings(session *session, settings *Sess return } } - + if session.HeartBtIntOverride || mustProvide { var heartBtInt int if heartBtInt, err = settings.IntSetting(config.HeartBtInt); err != nil { diff --git a/session_settings.go b/session_settings.go index 130bf9667..17889eccc 100644 --- a/session_settings.go +++ b/session_settings.go @@ -100,7 +100,7 @@ func (s *SessionSettings) DurationSetting(setting string) (val time.Duration, er return } -//BoolSetting returns the requested setting parsed as a boolean. Returns an errror if the setting is not set or cannot be parsed as a bool. +//BoolSetting returns the requested setting parsed as a boolean. Returns an error if the setting is not set or cannot be parsed as a bool. func (s SessionSettings) BoolSetting(setting string) (bool, error) { stringVal, err := s.Setting(setting) diff --git a/session_state.go b/session_state.go index c8b1f42a4..5b05284a2 100644 --- a/session_state.go +++ b/session_state.go @@ -218,7 +218,7 @@ type sessionState interface { //Stop triggers a clean stop Stop(*session) (nextState sessionState) - //debugging convenience + //Stringer debugging convenience fmt.Stringer } diff --git a/store_test.go b/store_test.go index 185704e52..7b8f6a2b8 100644 --- a/store_test.go +++ b/store_test.go @@ -113,22 +113,22 @@ func (s *MessageStoreTestSuite) TestMessageStore_SaveMessage_GetMessage() { s.Equal(expectedMsgsBySeqNum[3], string(actualMsgs[2])) } -func (suite *MessageStoreTestSuite) TestMessageStore_GetMessages_EmptyStore() { +func (s *MessageStoreTestSuite) TestMessageStore_GetMessages_EmptyStore() { // When messages are retrieved from an empty store - messages, err := suite.msgStore.GetMessages(1, 2) - require.Nil(suite.T(), err) + messages, err := s.msgStore.GetMessages(1, 2) + require.Nil(s.T(), err) // Then no messages should be returned - require.Empty(suite.T(), messages, "Did not expect messages from empty store") + require.Empty(s.T(), messages, "Did not expect messages from empty store") } -func (suite *MessageStoreTestSuite) TestMessageStore_GetMessages_VariousRanges() { - t := suite.T() +func (s *MessageStoreTestSuite) TestMessageStore_GetMessages_VariousRanges() { + t := s.T() // Given the following saved messages - require.Nil(t, suite.msgStore.SaveMessage(1, []byte("hello"))) - require.Nil(t, suite.msgStore.SaveMessage(2, []byte("cruel"))) - require.Nil(t, suite.msgStore.SaveMessage(3, []byte("world"))) + require.Nil(t, s.msgStore.SaveMessage(1, []byte("hello"))) + require.Nil(t, s.msgStore.SaveMessage(2, []byte("cruel"))) + require.Nil(t, s.msgStore.SaveMessage(3, []byte("world"))) // When the following requests are made to the store var testCases = []struct { @@ -148,7 +148,7 @@ func (suite *MessageStoreTestSuite) TestMessageStore_GetMessages_VariousRanges() // Then the returned messages should be for _, tc := range testCases { - actualMsgs, err := suite.msgStore.GetMessages(tc.beginSeqNo, tc.endSeqNo) + actualMsgs, err := s.msgStore.GetMessages(tc.beginSeqNo, tc.endSeqNo) require.Nil(t, err) require.Len(t, actualMsgs, len(tc.expectedBytes)) for i, expectedMsg := range tc.expectedBytes {