Dave Cheney | 06804de | 2018-01-06 14:25:34 +1100 | [diff] [blame] | 1 | This page gives some hints on how to successfully ask for help in the various [Go support forums][3]. |
Dave Cheney | 827829f | 2018-01-06 14:19:58 +1100 | [diff] [blame] | 2 | |
| 3 | ## Before you ask your question |
| 4 | |
| 5 | Before asking for help, please check that you've addressed the following common issues: |
| 6 | |
| 7 | ### Always check all errors |
| 8 | |
Dave Cheney | 7929844 | 2018-01-06 18:33:59 +1100 | [diff] [blame] | 9 | Always check all errors. It is common to see problems reported related to nil panics due to code like this |
Dave Cheney | 827829f | 2018-01-06 14:19:58 +1100 | [diff] [blame] | 10 | ``` |
Dave Cheney | c4854d2 | 2018-01-06 14:24:39 +1100 | [diff] [blame] | 11 | result, err := somefunction() |
Dave Cheney | 827829f | 2018-01-06 14:19:58 +1100 | [diff] [blame] | 12 | if 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 Cheney | 7785a2e | 2018-01-06 14:24:24 +1100 | [diff] [blame] | 18 | or |
| 19 | ``` |
| 20 | result, _ := somefunction() |
| 21 | // code uses result which might be invalid |
| 22 | ``` |
| 23 | You should make sure it is clear that your code is correctly handling all error conditions before asking for help. |
Dave Cheney | 827829f | 2018-01-06 14:19:58 +1100 | [diff] [blame] | 24 | |
| 25 | Further reading: |
| 26 | - [Error handling and Go][0] |
| 27 | |
Dave Cheney | 0a21a8e | 2018-01-06 18:58:55 +1100 | [diff] [blame] | 28 | ### Check that your code is free from data races |
Dave Cheney | 827829f | 2018-01-06 14:19:58 +1100 | [diff] [blame] | 29 | |
| 30 | Unexpected 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 | |
| 32 | If your program has good test coverage you can test for races by adding the `-race` flag to your `go test` invocation. |
| 33 | |
| 34 | If 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 | |
| 38 | Further reading: |
| 39 | - [Introducing the race detector][1] |
| 40 | |
| 41 | ## Asking questions |
| 42 | |
| 43 | The best way to get help is to show |
| 44 | |
Dave Cheney | e96104b | 2018-01-06 16:55:17 +1100 | [diff] [blame] | 45 | 1. **What you did, ideally with a small complete, stand-alone, example.** |
Dave Cheney | 9de7c03 | 2018-01-06 14:28:04 +1100 | [diff] [blame] | 46 | 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. |
| 47 | 2. **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 Cheney | 827829f | 2018-01-06 14:19:58 +1100 | [diff] [blame] | 48 | 3. **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 Cheney | 06804de | 2018-01-06 14:25:34 +1100 | [diff] [blame] | 59 | [2]: https://play.golang.org |
| 60 | [3]: https://github.com/golang/go/wiki/questions |