Skip to content

Commit

Permalink
完善因调用不存在的规则导致的panic的错误,改用正常错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
andeya committed Nov 21, 2016
1 parent 009ca2e commit b7ce281
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/spider/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,17 @@ func (self *Context) Aid(aid map[string]interface{}, ruleName ...string) interfa

_, rule, found := self.getRule(ruleName...)
if !found {
logs.Log.Error("蜘蛛 %s 调用Aid()时,指定的规则名不存在!", self.spider.GetName())
if len(ruleName) > 0 {
logs.Log.Error("调用蜘蛛 %s 不存在的规则: %s", self.spider.GetName(), ruleName[0])
} else {
logs.Log.Error("调用蜘蛛 %s 的Aid()时未指定的规则名", self.spider.GetName())
}
return nil
}
if rule.AidFunc == nil {
logs.Log.Error("蜘蛛 %s 的规则 %s 未定义AidFunc", self.spider.GetName(), ruleName[0])
return nil
}

return rule.AidFunc(self, aid)
}

Expand All @@ -327,6 +334,10 @@ func (self *Context) Parse(ruleName ...string) *Context {
self.spider.RuleTree.Root(self)
return self
}
if rule.ParseFunc == nil {
logs.Log.Error("蜘蛛 %s 的规则 %s 未定义ParseFunc", self.spider.GetName(), ruleName[0])
return self
}
rule.ParseFunc(self)
return self
}
Expand Down

0 comments on commit b7ce281

Please sign in to comment.