Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions pkg/parser/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ import (
)

var (
ErrRuleNotFound = errors.New("rule not found")
ErrNotSupported = errors.New("not supported")
ErrTermNotFound = errors.New("term not found")
ErrMissingOrder = errors.New("'sequence' missing 'order'")
ErrMissingMatch = errors.New("'set' missing 'match'")
ErrInvalidWindow = errors.New("invalid 'window'")
ErrTermsMapping = errors.New("'terms' must be a mapping")
ErrDuplicateTerm = errors.New("duplicate term name")
ErrMissingRuleId = errors.New("missing rule id")
ErrMissingRuleHash = errors.New("missing rule hash")
ErrMissingCreId = errors.New("missing cre id")
ErrInvalidCreId = errors.New("invalid cre id")
ErrInvalidRuleId = errors.New("invalid rule id (must be base58)")
ErrInvalidRuleHash = errors.New("invalid rule hash (must be base58)")
ErrRuleNotFound = errors.New("rule not found")
ErrRuleRootNotFound = errors.New("missing rule section")
ErrNotSupported = errors.New("not supported")
ErrTermNotFound = errors.New("term not found")
ErrMissingOrder = errors.New("'sequence' missing 'order'")
ErrMissingMatch = errors.New("'set' missing 'match'")
ErrInvalidWindow = errors.New("invalid 'window'")
ErrTermsMapping = errors.New("'terms' must be a mapping")
ErrDuplicateTerm = errors.New("duplicate term name")
ErrMissingRuleId = errors.New("missing rule id")
ErrMissingRuleHash = errors.New("missing rule hash")
ErrMissingCreId = errors.New("missing cre id")
ErrInvalidCreId = errors.New("invalid cre id")
ErrInvalidRuleId = errors.New("invalid rule id (must be base58)")
ErrInvalidRuleHash = errors.New("invalid rule hash (must be base58)")
)

var (
Expand Down Expand Up @@ -220,7 +221,13 @@ func buildTree(termsT map[string]ParseTermT, r ParseRuleT, ruleNode *yaml.Node,

n, ok = findChild(ruleNode, docRule)
if !ok {
return nil, root.WrapError(ErrRuleNotFound)
return nil, pqerr.Wrap(
pqerr.Pos{Line: ruleNode.Line, Col: ruleNode.Column},
r.Metadata.Id,
r.Metadata.Hash,
r.Cre.Id,
ErrRuleRootNotFound,
)
}

switch {
Expand Down Expand Up @@ -273,7 +280,13 @@ func buildSequenceTree(root *NodeT, termsT map[string]ParseTermT, r ParseRuleT,

orderYn, ok = findChild(ruleNode, docOrder)
if !ok {
return nil, root.WrapError(ErrMissingOrder)
return nil, pqerr.Wrap(
pqerr.Pos{Line: ruleNode.Line, Col: ruleNode.Column},
r.Metadata.Id,
r.Metadata.Hash,
r.Cre.Id,
ErrMissingOrder,
)
}

// Negate is optional
Expand Down Expand Up @@ -313,7 +326,13 @@ func buildSetTree(root *NodeT, termsT map[string]ParseTermT, r ParseRuleT, ruleN

matchYn, ok = findChild(ruleNode, docMatch)
if !ok {
return nil, root.WrapError(ErrMissingMatch)
return nil, pqerr.Wrap(
pqerr.Pos{Line: ruleNode.Line, Col: ruleNode.Column},
r.Metadata.Id,
r.Metadata.Hash,
r.Cre.Id,
ErrMissingMatch,
)
}

// Negate is optional
Expand Down