The use of regex.MustCompile (see:
|
func compileRegex(flags, expr string) *regexp.Regexp { |
|
if flags == "" { |
|
return regexp.MustCompile(expr) |
|
} else { |
|
return regexp.MustCompile(fmt.Sprintf("(?%s)%s", flags, expr)) |
|
} |
|
} |
) means that if any regex fails, there is a panic.
We pull down the master regex url daily, so that our regexes are always up to date, and load it right into our servers. The panic cause all our servers to crash last night, until we pinned the master regex url to a working version.
NewFromBytes already has the option to return an error, so why not return the error there?
|
func NewFromBytes(data []byte) (*Parser, error) { |
|
var definitions RegexesDefinitions |
|
if err := yaml.Unmarshal(data, &definitions); err != nil { |
|
return nil, err |
|
} |
|
|
|
parser := &Parser{definitions, 0, 0, 0, (EOsLookUpMode|EUserAgentLookUpMode|EDeviceLookUpMode), false, false} |
|
parser.mustCompile() |
|
|
|
return parser, nil |
|
} |
The use of regex.MustCompile (see:
uap-go/uaparser/parser.go
Lines 354 to 360 in daf92ba
We pull down the master regex url daily, so that our regexes are always up to date, and load it right into our servers. The panic cause all our servers to crash last night, until we pinned the master regex url to a working version.
NewFromBytes already has the option to return an error, so why not return the error there?
uap-go/uaparser/parser.go
Lines 209 to 219 in daf92ba