Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议 Event Name 检查出错后返回 error,而不是直接 panic #66

Open
flyinghail opened this issue Apr 6, 2024 · 0 comments
Open
Labels
question Further information is requested

Comments

@flyinghail
Copy link

flyinghail commented Apr 6, 2024

目前库中,检查 Event Name 不符合规则后会直接 panic,逻辑隐蔽,处理粗暴,很容易被坑。

建议改成返回 error

相关代码见 util.go:

// goodName check event name is valid.
func goodName(name string, isReg bool) string {
	name = strings.TrimSpace(name)
	if name == "" {
		panic("event: the event name cannot be empty")
	}

	// on add listener
	if isReg {
		if name == AllNode || name == Wildcard {
			return Wildcard
		}
		if strings.HasPrefix(name, AllNode) {
			return name
		}
	}

	if !goodNameReg.MatchString(name) {
		panic(`event: name is invalid, must match regex:` + goodNameReg.String())
	}
	return name
}
@inhere inhere added the question Further information is requested label Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants