10000 chore(qa): improve error checking · symfony-cli/symfony-cli@505fae7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 505fae7

Browse files
committed
chore(qa): improve error checking
1 parent e36ff9b commit 505fae7

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

.golangci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ linters:
2727
- github.com/symfony-cli/terminal.Eprintln
2828
- github.com/symfony-cli/terminal.Eprintfln
2929
- github.com/symfony-cli/terminal.Eprint
30+
- github.com/symfony-cli/terminal.SetLogLevel
3031
- fmt.Fprintln
3132
- fmt.Fprintf
3233
- fmt.Fprint
34+
exclusions:
35+
presets:
36+
- std-error-handling
37+
- common-false-positives
38+
rules:
39+
- path: _test\.go
40+
linters:
41+
- errcheck
42+
text: "(?i)Error return value of .(os\\.(Chdir|Rename)|io\\.Copy). is not checked"
43+
- path: _test\.go
44+
linters:
45+
- errcheck
46+
text: "(?i)Error return value of .flags\\.Set. is not checked"

local/php/executor_test.go

Lines changed: 17 additions & 5 deletions
O 10000 riginal file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ func testStdoutCapture(c *C, dst io.Writer) func() {
5959

6060
return func() {
6161
// Close the writer end of the pipe
62-
w.Sync()
63-
w.Close()
62+
if err := w.Sync(); err != nil {
63+
c.Fatalf("err: %s", err)
64+
}
65+
if err := w.Close(); err != nil {
66+
c.Fatalf("err: %s", err)
67+
}
6468

6569
// Reset stdout
6670
os.Stdout = old
@@ -213,7 +217,11 @@ func (s *ExecutorSuite) TestEnvInjection(c *C) {
213217
os.Chdir(filepath.Join(home, "project"))
214218

215219
os.Rename("git", ".git")
216-
defer os.Rename(".git", "git")
220+
defer func() {
221+
// handling error is not really worth it here: we could not really recover it anyway and the original directory
222+
// is commited
223+
_ = os.Rename(".git", "git")
224+
}()
217225
defer cleanupExecutorTempFiles()
218226

219227
var output bytes.Buffer
@@ -232,8 +240,12 @@ func (s *ExecutorSuite) TestEnvInjection(c *C) {
232240
projectFile := filepath.Join(".platform", "local", "project.yaml")
233241
contents, err := os.ReadFile(projectFile)
234242
c.Assert(err, IsNil)
235-
defer os.WriteFile(projectFile, contents, 0644)
236-
os.WriteFile(projectFile, bytes.Replace(contents, []byte("bew7pfa7t2ut2"), []byte("aew7pfa7t2ut2"), 1), 0644)
243+
defer func() {
244+
// handling error is not really worth it here: we could not really recover it and anyway the original file
245+
// content is commited
246+
_ = os.WriteFile(projectFile, contents, 0644)
247+
}()
248+
c.Assert(os.WriteFile(projectFile, bytes.Replace(contents, []byte("bew7pfa7t2ut2"), []byte("aew7pfa7t2ut2"), 1), 0644), IsNil)
237249

238250
output.Reset()
239251
outCloser = testStdoutCapture(c, &output)

local/proxy/proxy_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (s *ProxySuite) TestProxy(c *C) {
5959
TLD: "wip",
6060
path: "testdata/.symfony5/proxy.json",
6161
}, ca, log.New(zerolog.New(os.Stderr), "", 0), true)
62-
os.MkdirAll("testdata/.symfony5", 0755)
62+
c.Assert(os.MkdirAll("testdata/.symfony5", 0755), IsNil)
6363
err = p.Save()
6464
c.Assert(err, IsNil)
6565

@@ -172,15 +172,16 @@ func (s *ProxySuite) TestProxy(c *C) {
172172
{
173173
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
174174
w.WriteHeader(200)
175-
w.Write([]byte(`http://symfony-no-tls.wip`))
175+
_, err := w.Write([]byte(`http://symfony-no-tls.wip`))
176+
c.Assert(err, IsNil)
176177
}))
177178
defer backend.Close()
178179
backendURL, err := url.Parse(backend.URL)
179180
c.Assert(err, IsNil)
180181

181182
p := pid.New("symfony_com_no_tls", nil)
182183
port, _ := strconv.Atoi(backendURL.Port())
183-
p.Write(os.Getpid(), port, "http")
184+
c.Assert(p.Write(os.Getpid(), port, "http"), IsNil)
184185

185186
req, _ := http.NewRequest("GET", "http://symfony-no-tls.wip/", nil)
186187
req.Close = true

0 commit comments

Comments
 (0)
0