Skip to content

Commit de4229c

Browse files
Adding more context information to the errors
1 parent 94d7217 commit de4229c

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

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)

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

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 {

session_settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (s *SessionSettings) DurationSetting(setting string) (val time.Duration, er
100100
return
101101
}
102102

103-
//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.
103+
//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.
104104
func (s SessionSettings) BoolSetting(setting string) (bool, error) {
105105
stringVal, err := s.Setting(setting)
106106

0 commit comments

Comments
 (0)