Skip to content

Commit 2449f0f

Browse files
authored
fix: [#9] wrap error in example (#14)
1 parent 0967617 commit 2449f0f

File tree

5 files changed

+92
-20
lines changed

5 files changed

+92
-20
lines changed

.github/workflows/golang.yml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,23 @@ permissions:
1111
packages: read
1212
jobs:
1313
mcvs-golang-action:
14-
# yamllint disable rule:braces
15-
# yamllint disable rule:indentation
1614
strategy:
1715
matrix:
1816
args:
19-
- { testing-type: "component" }
20-
- { testing-type: "coverage" }
21-
- { testing-type: "integration" }
22-
- { testing-type: "lint", build-tags: "component" }
23-
- { testing-type: "lint", build-tags: "e2e" }
24-
- { testing-type: "lint", build-tags: "integration" }
25-
- { testing-type: "security-golang-modules" }
26-
- { testing-type: "security-grype" }
27-
- { testing-type: "security-trivy" }
28-
- { testing-type: "unit" }
29-
runs-on: ubuntu-22.04
30-
# yamllint enable rule:braces
31-
# yamllint enable rule:indentation
17+
- testing-type: "component"
18+
- testing-type: "coverage"
19+
- testing-type: "integration"
20+
- testing-type: "lint"
21+
build-tags: "component"
22+
- testing-type: "lint"
23+
build-tags: "e2e"
24+
- testing-type: "lint"
25+
build-tags: "integration"
26+
- testing-type: "security-golang-modules"
27+
- testing-type: "security-grype"
28+
- testing-type: "security-trivy"
29+
- testing-type: "unit"
30+
runs-on: ubuntu-24.04
3231
env:
3332
TASK_X_REMOTE_TASKFILES: 1
3433
steps:

.golangci.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# yamllint disable rule:line-length
2+
---
3+
version: "2"
4+
linters:
5+
default: all
6+
disable:
7+
# err113 is disabled as it does not make any sense to use wrapped static
8+
# errors as it contains superfluous escaped double quotes.
9+
- err113
10+
# exhaustruct is disabled as there are scenarios in this code base where a
11+
# some keys of a struct should be empty while testing.
12+
- exhaustruct
13+
# gochecknoglobals is disabled as there are global errors and component
14+
# test variables.
15+
- gochecknoglobals
16+
# lll is disabled as there too many long lines in this project. Sometimes
17+
# function names and struct names that are returned are combined too long,
18+
# other times the error messages that are being checked are exceeding 120
19+
# chars. To stop the leakage, all team members have been requested to
20+
# set a ruler in vscode for go code to 120 chars.
21+
- lll
22+
- noctx
23+
# testpackage is disabled as it is a bad practice to make methods public to
24+
# be able to test them.
25+
- testpackage
26+
settings:
27+
depguard:
28+
rules:
29+
main:
30+
files:
31+
- "!**/*_a _file.go"
32+
allow:
33+
- $gostd
34+
- github.com/schubergphilis/mcvs-golang-project-root/pkg/projectroot
35+
- github.com/sirupsen/logrus
36+
deny:
37+
- pkg: log
38+
desc: Use 'log "github.com/sirupsen/logrus"' instead
39+
- pkg: github.com/pkg/errors
40+
desc: Should be replaced by standard lib errors package
41+
exclusions:
42+
generated: lax
43+
presets:
44+
- comments
45+
- common-false-positives
46+
- legacy
47+
- std-error-handling
48+
paths:
49+
- internal/app/mcvs-scanner-cli/application/swagger
50+
- third_party$
51+
- builtin$
52+
- examples$
53+
rules:
54+
- linters:
55+
- funlen
56+
path: _test\.go
57+
formatters:
58+
enable:
59+
- gci
60+
- gofmt
61+
- gofumpt
62+
- goimports
63+
exclusions:
64+
generated: lax
65+
paths:
66+
- internal/app/mcvs-scanner-cli/application/swagger
67+
- third_party$
68+
- builtin$
69+
- examples$

Taskfile.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ version: 3
33

44
vars:
55
REMOTE_URL: https://raw.githubusercontent.com
6-
REMOTE_URL_REF: v0.17.6
6+
REMOTE_URL_REF: v2.0.0
77
REMOTE_URL_REPO: schubergphilis/mcvs-golang-action
88

99
includes:
1010
remote:
1111
taskfile: >-
12-
{{.REMOTE_URL}}/{{.REMOTE_URL_REPO}}/{{.REMOTE_URL_REF}}/Taskfile.yml
12+
{{.REMOTE_URL}}/{{.REMOTE_URL_REPO}}/{{.REMOTE_URL_REF}}/build/task.yml

examples/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
func main() {
99
projectRoot, err := projectroot.FindProjectRoot()
1010
if err != nil {
11-
log.WithFields(log.Fields{"err": err}).Fatal("unable to find project root")
11+
log.WithError(err).Fatal("unable to find project root")
1212
}
13+
1314
log.Infof("project root found at: %s", projectRoot)
1415
}

pkg/projectroot/projectroot.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package projectroot
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -10,7 +11,7 @@ import (
1011
func FindProjectRoot() (string, error) {
1112
currentDir, err := os.Getwd()
1213
if err != nil {
13-
return "", err
14+
return "", fmt.Errorf("unable to return path for the corresponding current working dir: %w", err)
1415
}
1516

1617
for {
@@ -22,13 +23,15 @@ func FindProjectRoot() (string, error) {
2223
if currentDir == parentDir {
2324
break
2425
}
26+
2527
currentDir = parentDir
2628
}
2729

28-
return "", fmt.Errorf("project root not found")
30+
return "", errors.New("project root not found")
2931
}
3032

3133
func fileExists(path string) bool {
3234
_, err := os.Stat(path)
35+
3336
return !os.IsNotExist(err)
3437
}

0 commit comments

Comments
 (0)