Skip to content

Commit 19f036e

Browse files
committed
chore(qa): improve error checking
1 parent e36ff9b commit 19f036e

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-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: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ 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.Close(); err != nil {
63+
c.Errorf("err: %s", err)
64+
}
6465

6566
// Reset stdout
6667
os.Stdout = old
@@ -213,7 +214,11 @@ func (s *ExecutorSuite) TestEnvInjection(c *C) {
213214
os.Chdir(filepath.Join(home, "project"))
214215

215216
os.Rename("git", ".git")
216-
defer os.Rename(".git", "git")
217+
defer func() {
218+
// handling error is not really worth it here: we could not really recover it anyway and the original directory
219+
// is commited
220+
_ = os.Rename(".git", "git")
221+
}()
217222
defer cleanupExecutorTempFiles()
218223

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

238247
output.Reset()
239248
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy