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

x/playground: do the "vet" check along with running a program #24576

Closed
ysmolski opened this issue Mar 28, 2018 · 18 comments
Closed

x/playground: do the "vet" check along with running a program #24576

ysmolski opened this issue Mar 28, 2018 · 18 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@ysmolski
Copy link
Member

ysmolski commented Mar 28, 2018

"vet" is implemented as a separate button. Consider if we can remove that button and do the "vet" check whenever a user pushes the "run" button.

Comments from CL 100776:

Bryan Mills
I wonder whether this should even be a separate button. Could we Vet unconditionally whenever we Run?

We already have a bit of a visual distinction between “errors” and “output”, so it probably wouldn't be terribly confusing to put the errors before the output if we have both, and that would make the warnings that much more discoverable.

Nathan Youngman
I think that's a good point.

Also, with the Go Playground supporting tests, and tests in Go 1.10 now running a subset of vet, it seems like this could just be automatic whether running tests or code. Though it may be important to clearly indicate what is an error from the compiler vs. an error from vet for people new to Go.

https://go-review.googlesource.com/c/playground/+/98155

Andrew Bonventre
This would have ramifications for every call to /compile, which is an endpoint that anyone can use right now.

Yury Smolsky
That would mean changing the spec of /compile endpoint. That endpoint is not supposed to return errors along with output. All clients assume that if there is an error, then output should not be considered. So this could break clients. IMHO, this feature requires new version of /compile along with new protocol.

Nathan Youngman
There is more than one way to do it. An alternative is for the front-end to call /compile and /vet from the same button click.

https://go-review.googlesource.com/c/playground/+/100776/5/edit.html#115

@gopherbot gopherbot added this to the Unreleased milestone Mar 28, 2018
@ALTree ALTree added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 28, 2018
@ghost
Copy link

ghost commented Mar 29, 2018

No way. Refusing to run perfectly correct programs isn't what one expects of a playground, for Zeus's sake.

fmt.Println("Is it?\n") // vet: redundant newline

@ysmolski
Copy link
Member Author

It is not supposed that "vet" errors will prevent from executing the program. Errors from vet must be displayed along with output from the program. However how to present it clearly, I don't know.

@rsc
Copy link
Contributor

rsc commented Apr 9, 2018

Back end protocol aside (that can be worked out either way), it does seem nice to just show the vet output alongside the normal output, instead of having yet another button. Unlike go test, if vet fails, the program should still run. (This is the playground.)

@nathany
Copy link
Contributor

nathany commented Apr 13, 2018

Now that the playground supports go test (#6511) is there any interplay to consider between go test running vet and running vet standalone? Or would the vet part of go test just be disabled/ignored in the playground in favour of the same vet as non-test code?

Regarding back end, what makes most sense to me at the moment is separate vet and compile endpoints that the UI can use from the same button click. What happens when the compile fails with errors though? Does vet only run after the compile succeeds and the output (begins) to display? (Keeping in mind time.Sleep works in the playground).

@ysmolski
Copy link
Member Author

ysmolski commented Apr 14, 2018

To clarify go test function of Playground. Right now it does not run vet while testing. So we assume that we have to run go vet for the code containing tests too. And errors returned from go vet should not break an execution of a program even for tests. It differs from the behaviour of a real 'go test', but this will provide some consistency for the playground users.

EDIT: removed spammy examples from here.

@ysmolski
Copy link
Member Author

ysmolski commented Apr 15, 2018

I have made the output of stderr to look like an error and put vet errors before the output. It is not indicated that first error is from vet. Should we?

screen shot 2018-04-15 at 10 16 20

Running an example without output compiles it but does not executes. Produces this error:

screen shot 2018-04-15 at 10 19 28

@ysmolski ysmolski changed the title x/playground: do the "vet" check before running user programs x/playground: do the "vet" check along with running a program Apr 16, 2018
@gopherbot
Copy link

Change https://golang.org/cl/107455 mentions this issue: godoc: display "go vet" errors before the output of a program

@gopherbot
Copy link

Change https://golang.org/cl/100776 mentions this issue: playground: add vet

@bcmills
Copy link
Contributor

bcmills commented Apr 16, 2018

All of these formats seem to rely on differences in color, which might not work so well for someone with red-green colorblindness, although I suppose that's also an existing issue.

To distinguish vet output from user code, what about putting the vet output at the end of the affected line instead of after the program?

That might look like:
screenshot 2018-04-16 at 15 56 29

That way the warning isn't buried at the end of the output, but also doesn't bury the output. On the other hand, line-wrapping makes things a bit dicey for small windows, long code lines, and/or long error lines.

@jimmyfrasche
Copy link
Member

Red/black can look a lot like black/black or black/nearly-black for various forms of color blindness and mostly for red-green color blindness which is the most prevalent form.

Another way to distinguish the vet output is to leave it where it is but draw a box around it labeled something like "vet output".

The red issue also applies to stdout vs stderr. Maybe adding unhighlightable {out, err} labels where line numbers would go in addition to the red? They could be made smallish since they'd essentially be icons. The lack of either on vet warnings would probably be enough to make it clear where things start and stop along with a little more spacing between the vet output and the program output.

@ysmolski
Copy link
Member Author

ysmolski commented Apr 16, 2018

More screenshots for my proposed solution/design above: https://imgur.com/a/Jn3qx.

Thanks for the feedback. I will meditate on it.

Feel free to add more. For some reason I am not satisfied with my proposed design anymore. It has apparent flaws. 7 years of pure programming have put too much rust on my design/layout skills.

@ysmolski
Copy link
Member Author

I don't want to add graphics for this feature. I really like simple or minimal design as it is right now. Also I want vet errors to be on the top, that they urge a user to fix the code and get rid of them. They must be annoying in some sense.

Is current design friendly to color blind people?

I propose this simple layout:
screen shot 2018-04-20 at 23 39 02

If go vet returned no errors, then first 3 lines are not displayed.

@jimmyfrasche
Copy link
Member

The explicit delimiter works. It's not friendly, per se—but it's not antagonistic.

@ysmolski
Copy link
Member Author

One more observation:

package main

func main() {
	qwe
}

produces

prog.go:4:2: undefined: qwe

Program exited.

But in fact the program was not running at all. Error came from the go build. So the output could be:

prog.go:4:2: undefined: qwe

Go build exited.

@jimmyfrasche
Copy link
Member

"Go build failed." might be clearer. It always exits.

@bcmills
Copy link
Contributor

bcmills commented Apr 24, 2018

We should ensure that vet results show up in the Tour, too. That might save some folks a lot of time while they're learning.

@ysmolski
Copy link
Member Author

ysmolski commented May 3, 2018

I agree. Tour is a different thing and does things differently. It uses golang.org/compile. Since we add new endpoint for vetting, we do not break Tour by any means. So that feature is still possible and should be tackled as a separate change.

I have updated https://go-review.googlesource.com/c/tools/+/107455 with the proposal I made above. I think this is the best design retaining simplicity I can think of. Examples are here.

@ysmolski
Copy link
Member Author

ysmolski commented May 8, 2018

@andybons, please take a look at https://go-review.googlesource.com/c/tools/+/107455.

gopherbot pushed a commit to golang/tools that referenced this issue May 8, 2018
This change adds an option to run "go vet" for the playground program
and display errors before any output. To enable this, the playground
function has to be supplied with opts.enableVet set to true.
Vet check is performed only for succesfully run programs,
meaning that the "/compile" endpoint returned no errors.

This change highlights lines printed to stderr as errors (in red).

There is a corresponding change for the Playground: CL 100776.

Updates golang/go#7597
Updates golang/go#24576

Change-Id: I8c0f8c1189c461338b5bce57777b12aecab268fb
Reviewed-on: https://go-review.googlesource.com/107455
Run-TryBot: Yury Smolsky <yury@smolsky.by>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
@ysmolski ysmolski self-assigned this Oct 26, 2018
@golang golang locked and limited conversation to collaborators Oct 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

7 participants