blob: 9f816ac4698246a20b9e2e2cc926f8d97ed76c8b [file] [log] [blame] [view]
Dave Cheney06804de2018-01-06 14:25:34 +11001This page gives some hints on how to successfully ask for help in the various [Go support forums][3].
Dave Cheney827829f2018-01-06 14:19:58 +11002
3## Before you ask your question
4
5Before asking for help, please check that you've addressed the following common issues:
6
7### Always check all errors
8
Dave Cheney79298442018-01-06 18:33:59 +11009Always check all errors. It is common to see problems reported related to nil panics due to code like this
Dave Cheney827829f2018-01-06 14:19:58 +110010```
Dave Cheneyc4854d22018-01-06 14:24:39 +110011result, err := somefunction()
Dave Cheney827829f2018-01-06 14:19:58 +110012if err != nil {
13 log.Println("oops an error happened", err)
14 // return is missing here
15}
16// the code then continues to use result which is invalid.
17```
Dave Cheney7785a2e2018-01-06 14:24:24 +110018or
19```
20result, _ := somefunction()
21// code uses result which might be invalid
22```
23You should make sure it is clear that your code is correctly handling all error conditions before asking for help.
Dave Cheney827829f2018-01-06 14:19:58 +110024
25Further reading:
26- [Error handling and Go][0]
27
Dave Cheney0a21a8e2018-01-06 18:58:55 +110028### Check that your code is free from data races
Dave Cheney827829f2018-01-06 14:19:58 +110029
30Unexpected runtime panics are often caused by data races in your program. If your program contains a data race you need to address the race before asking for help.
31
32If your program has good test coverage you can test for races by adding the `-race` flag to your `go test` invocation.
33
34If your program does not have good test coverage or the crash only happens when running the program, you can build a race enabled version of your program by passing `-race` to your `go build` or `go install` invocation.
35
36_The behaviour of a Go program with a data race is undefined. There are no safe data races in Go programs._
37
38Further reading:
39- [Introducing the race detector][1]
40
41## Asking questions
42
43The best way to get help is to show
44
Dave Cheneye96104b2018-01-06 16:55:17 +1100451. **What you did, ideally with a small complete, stand-alone, example.**
Dave Cheney9de7c032018-01-06 14:28:04 +110046 If you ran a command, show the command that you ran. If your program failed, provide the source of the program that failed. If the program is too large, or you cannot share the source, instead provide a self contained, runnable example, that demonstrates the problem.
472. **What you expected to happen.** If you expected the command to complete successfully, say that. If you expected the program to produce a particular output, give an example of the output you expected.
Dave Cheney827829f2018-01-06 14:19:58 +1100483. **What happened instead.**
49 If the command failed, include the full output of the failure, not just a single line that you though was the cause. If the program failed to produce the expected output, include what it did output.
50
51## Additional tips
52
53- If you are posting the output of a command, paste the text, not a screenshot of the text. If it's actually an image, that's ok.
54- If you are posting a large amount of output, you may consider using a pastebin or gist service.
55- When posting code samples, use the [Go playground][2] (unless it is unavailable in your country).
56
57[0]: https://blog.golang.org/error-handling-and-go
58[1]: https://blog.golang.org/race-detector
Dave Cheney06804de2018-01-06 14:25:34 +110059[2]: https://play.golang.org
60[3]: https://github.com/golang/go/wiki/questions