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

Proposal: Add static checker to ensure return when an error occurs in api handlers #23

Draft
wants to merge 6 commits into
base: new
Choose a base branch
from

Conversation

AGMETEOR
Copy link

@AGMETEOR AGMETEOR commented Jul 25, 2021

Summary

This PR adds code for a new static checker that checks whether when an error occurs in api handler, we return.

See some cases below:

mattermost-vet will flag this

func a(c *Context, w http.ResponseWriter, r *http.Request) {
	err := iR()
	if err != nil { // not ok
		c.Err = err
	}
}

mattermost-vet will not flag this

func b(c *Context, w http.ResponseWriter, r *http.Request) {
	err := iR()
	if err != nil { // ok
		c.Err = err
                 return
	}
}

mattermost-vet will not include this static checker in this handler

// skip appErrReturn check
func q(c *Context, w http.ResponseWriter, r *http.Request) {
	err := iR()
	t := iR()
	s := true

	if t == nil && (err != nil) && s { // not ok but skipped
		c.Err = err
	}
}

@AGMETEOR AGMETEOR self-assigned this Jul 25, 2021
@AGMETEOR AGMETEOR marked this pull request as draft July 25, 2021 21:27
@agnivade agnivade changed the base branch from master to new September 1, 2021 16:58
@agnivade
Copy link
Member

agnivade commented Jan 7, 2022

Finally some updates :) Let me know whenever it is ready for review. Would be happy to take a look.

@AGMETEOR
Copy link
Author

AGMETEOR commented Jan 7, 2022

Finally some updates :) Let me know whenever it is ready for review. Would be happy to take a look.

Hey @agnivade , sure. Will let you know. Hopefully by Monday will be done and have a fully working analyzer

@hanzei hanzei added the Work In Progress Not yet ready for review label Dec 6, 2022
@mattermost-build
Copy link

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants