-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Print error message and exit with non-zero status when ruleguard parse error occurs #1666
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
Conversation
@quasilyte for review since he is the owner of gocritic and ruleguard. |
To test this feature, I used the following config file: linters:
enable:
- gocritic
linters-settings:
gocritic:
settings:
ruleguard:
failOnError: true
rules: rules.go Commands for test purpose: git clone https://github.com/golangci/golangci-lint.git
cd golangci-lint
# Update go mod to use the go-critic@master, which has support for the 'failOnError' flag.
go get -v github.com/go-critic/go-critic@master
make
# Create rules.go file containing ruleguard rules.
# Try with and without syntax errors in the rules.go file. |
Converted to draft because of:
|
A lib that throws a panic is not a good thing, seems to be a design flaw. |
Sure, that makes sense. It seems this is because the signature of The One potential issue is that @quasilyte , are you ok with these proposed changes in go-critic/go-critic#1020? |
|
@sebastien-rosset could you execute |
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR ensures that parsing errors of
ruleguard
input rules are caught; in that case, golangci-lint will print a human-friendly error message (include file name and line number) and exit with non-zero status. Without this PR, a verbose stack trace is printed.The ruleguard checker makes it possible to write dynamic rules, which means the rules files may have syntax errors that need to be caught. When a ruleguard parsing error occurs, golangci-lint will print the following message and exit.
ERRO Running error: gocritic: gocritic checker 'ruleguard' initialization failed: ruleguard init error: parse file error: rules.go:18:1: expected declaration, found FOO
The actual error is raised when the
failOnError
flag is set to true in the golangci.yaml file, as explained in go-critic/go-critic#1015.As of 01/25/2021, the latest
goangci-lint
release is v1.35.2. It uses gocritic v0.5.3, which does not have the newfailOnError
flag yet, but the go-critic/go-critic#1015 PR has already been merged to gocritic master. The error handling will be enabled in golangci-lint when 1) a new version of gocritic is released with support for thefailOnError
flag; and 2) golangci-lint needs to be bumped to the new gocritic version.Fixes #1565
Without this PR, a verbose stack trace is printed as shown below.