Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance linter and errors #1572

Merged
merged 74 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
b63efc5
specific linter issues
anbraten Feb 1, 2023
ad7a319
use multierr
anbraten Feb 1, 2023
7346a4b
improve linter
anbraten Feb 1, 2023
fe40a80
enhance linter
anbraten Feb 1, 2023
0aae003
fix tests
anbraten Feb 1, 2023
419bacb
Merge remote-tracking branch 'upstream/master' into specific-linter-i…
anbraten Feb 2, 2023
c62900f
Merge branch 'master' into specific-linter-issues
anbraten Mar 1, 2023
2590e32
improve error handling and add e2e pipeline compiler test
anbraten Mar 1, 2023
016dded
Merge remote-tracking branch 'upstream/master' into specific-linter-i…
anbraten May 11, 2023
a4d22de
Merge remote-tracking branch 'upstream/master' into specific-linter-i…
anbraten May 11, 2023
f396a65
fixes
anbraten May 14, 2023
9361ef8
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Aug 16, 2023
803bab8
Merge branch 'main' into specific-linter-issues
anbraten Aug 16, 2023
d31c765
undo change
anbraten Aug 16, 2023
c39037e
fix test code
anbraten Aug 16, 2023
4d59d62
improve error
anbraten Aug 20, 2023
89cb9f6
Merge branch 'main' into specific-linter-issues
anbraten Sep 13, 2023
1f8a2be
Merge branch 'specific-linter-issues' of github.com:anbraten/woodpeck…
anbraten Sep 13, 2023
00b1fab
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Sep 19, 2023
b53e505
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Oct 8, 2023
db8dcd5
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Oct 8, 2023
8100ca4
move test, some notes
anbraten Oct 8, 2023
290bfb6
fix error handling
anbraten Oct 10, 2023
11352dd
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Oct 10, 2023
ce65912
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Oct 23, 2023
49971b4
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Oct 24, 2023
9c22420
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Oct 24, 2023
43b8119
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Oct 24, 2023
59ec88e
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Oct 29, 2023
ecb582a
adjust error type
anbraten Oct 31, 2023
468e2c9
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Oct 31, 2023
404d3a1
improve errors
anbraten Oct 31, 2023
83c278a
simplify
anbraten Oct 31, 2023
e7fafb6
adjust error
anbraten Oct 31, 2023
80658c3
Merge branch 'main' into specific-linter-issues
6543 Oct 31, 2023
ef45661
add chk
anbraten Oct 31, 2023
0f418c5
Merge branch 'specific-linter-issues' of github.com:anbraten/woodpeck…
anbraten Nov 1, 2023
9373fd6
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Nov 1, 2023
5f1efa5
improve error handling
anbraten Nov 1, 2023
8db44ea
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Nov 1, 2023
6a553d4
improve lint command output
anbraten Nov 1, 2023
6ab8b8e
add todo
anbraten Nov 1, 2023
b496440
improve error returning
anbraten Nov 1, 2023
98454c1
update error view
anbraten Nov 1, 2023
c45c2e9
further adjustments
anbraten Nov 1, 2023
79cb449
improve logic
anbraten Nov 1, 2023
b6fffd3
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Nov 2, 2023
f9aafee
update path
anbraten Nov 2, 2023
e2ef7b5
undo
anbraten Nov 2, 2023
de07617
finish ui
anbraten Nov 2, 2023
dcf1cc4
fixes
anbraten Nov 2, 2023
a2b3635
show step error
anbraten Nov 2, 2023
b32e224
remove test
anbraten Nov 2, 2023
a5b33b0
add migration
anbraten Nov 2, 2023
8fe18e1
Apply suggestions from code review
anbraten Nov 2, 2023
7247367
rename linter fncs
anbraten Nov 2, 2023
278ae69
fix test
anbraten Nov 2, 2023
3cac41b
Merge branch 'specific-linter-issues' of github.com:anbraten/woodpeck…
anbraten Nov 2, 2023
27605e7
update woodpecker go
anbraten Nov 2, 2023
c9ec5bd
cleanup
anbraten Nov 2, 2023
7b080e3
undo
anbraten Nov 2, 2023
1f35813
undo
anbraten Nov 2, 2023
fab27b5
add test
anbraten Nov 2, 2023
1c531f4
Merge branch 'main' into specific-linter-issues
anbraten Nov 2, 2023
91f74da
Merge remote-tracking branch 'upstream/main' into specific-linter-issues
anbraten Nov 2, 2023
ebfa397
Merge branch 'specific-linter-issues' of github.com:anbraten/woodpeck…
anbraten Nov 2, 2023
30f4a1b
remove unused translation
anbraten Nov 2, 2023
1f0ec64
fix migration
anbraten Nov 2, 2023
add23be
update swagger docs
anbraten Nov 2, 2023
b94756e
fix migration again
anbraten Nov 3, 2023
6c0adce
Refactor pipeline YAML linter test and schema
anbraten Nov 3, 2023
b9f9b9a
fix tests
anbraten Nov 3, 2023
b83d4ae
fix pre commit
anbraten Nov 3, 2023
58c9a7f
remove unused check
anbraten Nov 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
rev: v2.3.0
hooks:
- id: check-yaml
exclude: 'pipeline/schema/.woodpecker/test-merge-map-and-sequence.yml'
exclude: 'pipeline/frontend/yaml/linter/schema/.woodpecker/test-merge-map-and-sequence.yml'
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/golangci/golangci-lint
Expand Down
2 changes: 1 addition & 1 deletion cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
}

// lint the yaml file
if lerr := linter.New(linter.WithTrusted(true)).Lint(conf); lerr != nil {
if lerr := linter.New(linter.WithTrusted(true)).Lint(confstr, conf); lerr != nil {
return lerr
}

Expand Down
54 changes: 48 additions & 6 deletions cli/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
package lint

import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"

"github.com/muesli/termenv"
"github.com/urfave/cli/v2"

"github.com/woodpecker-ci/woodpecker/cli/common"
"github.com/woodpecker-ci/woodpecker/pipeline/schema"
pipeline_errors "github.com/woodpecker-ci/woodpecker/pipeline/errors"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/linter"
)

// Command exports the info command.
Expand Down Expand Up @@ -68,21 +73,58 @@ func lintDir(c *cli.Context, dir string) error {
}

func lintFile(_ *cli.Context, file string) error {
output := termenv.NewOutput(os.Stdout)

fi, err := os.Open(file)
if err != nil {
return err
}
defer fi.Close()

configErrors, err := schema.Lint(fi)
buf, err := os.ReadFile(file)
if err != nil {
fmt.Println("❌ Config is invalid")
for _, configError := range configErrors {
fmt.Println("In", configError.Field()+":", configError.Description())
}
return err
}

rawConfig := string(buf)

c, err := yaml.ParseString(rawConfig)
if err != nil {
return err
}

err = linter.New(linter.WithTrusted(true)).Lint(string(buf), c)
if err != nil {
fmt.Printf("🔥 %s has errors:\n", output.String(path.Base(file)).Underline())

hasErrors := true
for _, err := range pipeline_errors.GetPipelineErrors(err) {
line := " "

if err.IsWarning {
line = fmt.Sprintf("%s ⚠️ ", line)
} else {
line = fmt.Sprintf("%s ❌", line)
hasErrors = true
}

if data := err.GetLinterData(); data != nil {
line = fmt.Sprintf("%s %s\t%s", line, output.String(data.Field).Bold(), err.Message)
} else {
line = fmt.Sprintf("%s %s", line, err.Message)
}

// TODO: use table output
fmt.Printf("%s\n", line)
}

if hasErrors {
return errors.New("config has errors")
}

return nil
}

fmt.Println("✅ Config is valid")
return nil
}
54 changes: 52 additions & 2 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3951,8 +3951,11 @@ const docTemplate = `{
"enqueued_at": {
"type": "integer"
},
"error": {
"type": "string"
"errors": {
"type": "array",
"items": {
"$ref": "#/definitions/errors.PipelineError"
}
},
"event": {
"$ref": "#/definitions/WebhookEvent"
Expand Down Expand Up @@ -4248,6 +4251,17 @@ const docTemplate = `{
"blocked",
"declined"
],
"x-enum-comments": {
"StatusBlocked": "waiting for approval",
"StatusDeclined": "blocked and declined",
"StatusError": "error with the config / while parsing / some other system problem",
"StatusFailure": "failed to finish (exit code != 0)",
"StatusKilled": "killed by user",
"StatusPending": "pending to be executed",
"StatusRunning": "currently running",
"StatusSkipped": "skipped as another step failed",
"StatusSuccess": "successfully finished"
},
"x-enum-varnames": [
"StatusSkipped",
"StatusPending",
Expand Down Expand Up @@ -4407,6 +4421,42 @@ const docTemplate = `{
"EventManual"
]
},
"errors.PipelineError": {
"type": "object",
"properties": {
"data": {},
"is_warning": {
"type": "boolean"
},
"message": {
"type": "string"
},
"type": {
"$ref": "#/definitions/errors.PipelineErrorType"
}
}
},
"errors.PipelineErrorType": {
"type": "string",
"enum": [
"linter",
"deprecation",
"compiler",
"generic"
],
"x-enum-comments": {
"PipelineErrorTypeCompiler": "some error with the config semantics",
"PipelineErrorTypeDeprecation": "using some deprecated feature",
"PipelineErrorTypeGeneric": "some generic error",
"PipelineErrorTypeLinter": "some error with the config syntax"
},
"x-enum-varnames": [
"PipelineErrorTypeLinter",
"PipelineErrorTypeDeprecation",
"PipelineErrorTypeCompiler",
"PipelineErrorTypeGeneric"
]
},
"model.Workflow": {
"type": "object",
"properties": {
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.17
github.com/moby/moby v24.0.7+incompatible
github.com/moby/term v0.5.0
github.com/muesli/termenv v0.15.2
github.com/oklog/ulid/v2 v2.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
Expand All @@ -47,6 +48,7 @@ require (
github.com/urfave/cli/v2 v2.25.7
github.com/xanzy/go-gitlab v0.93.2
github.com/xeipuuv/gojsonschema v1.2.0
go.uber.org/multierr v1.11.0
golang.org/x/crypto v0.14.0
golang.org/x/net v0.17.0
golang.org/x/oauth2 v0.13.0
Expand All @@ -67,6 +69,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down Expand Up @@ -107,9 +110,11 @@ require (
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/libdns/libdns v0.2.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mholt/acmez v1.2.0 // indirect
github.com/miekg/dns v1.1.55 // indirect
Expand All @@ -124,6 +129,7 @@ require (
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -136,7 +142,6 @@ require (
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/mod v0.13.0 // indirect
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4u
github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/antonmedv/expr v1.15.3 h1:q3hOJZNvLvhqE8OHBs1cFRdbXFNKuA+bHmRaI+AmRmI=
github.com/antonmedv/expr v1.15.3/go.mod h1:0E/6TxnOlRNp81GMzX9QfDPAmHo2Phg00y4JUv1ihsE=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -175,8 +177,6 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/google/tink/go v1.7.0 h1:6Eox8zONGebBFcCBqkVmt60LaWZa6xg1cl/DwAh/J1w=
github.com/google/tink/go v1.7.0/go.mod h1:GAUOd+QE3pgj9q8VKIGTCP33c/B7eb4NhxLcgTJZStM=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
Expand Down Expand Up @@ -272,6 +272,8 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/libdns/libdns v0.2.1 h1:Wu59T7wSHRgtA0cfxC+n1c/e+O3upJGWytknkmFEDis=
github.com/libdns/libdns v0.2.1/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
Expand All @@ -292,6 +294,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
Expand All @@ -314,6 +318,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
Expand Down Expand Up @@ -350,6 +356,8 @@ github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwa
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down Expand Up @@ -666,7 +674,5 @@ sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
xorm.io/xorm v1.3.3 h1:L5/GOhvgMcwJYYRjzPf3lTTTf6JcaTd1Mb9A/Iqvccw=
xorm.io/xorm v1.3.3/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
xorm.io/xorm v1.3.4 h1:vWFKzR3DhGUDl5b4srhUjhDwjxkZAc4C7BFszpu0swI=
xorm.io/xorm v1.3.4/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
77 changes: 77 additions & 0 deletions pipeline/errors/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package errors

import (
"errors"
"fmt"

"go.uber.org/multierr"
)

type PipelineErrorType string

const (
PipelineErrorTypeLinter PipelineErrorType = "linter" // some error with the config syntax
PipelineErrorTypeDeprecation PipelineErrorType = "deprecation" // using some deprecated feature
PipelineErrorTypeCompiler PipelineErrorType = "compiler" // some error with the config semantics
PipelineErrorTypeGeneric PipelineErrorType = "generic" // some generic error
)

type PipelineError struct {
Type PipelineErrorType `json:"type"`
Message string `json:"message"`
IsWarning bool `json:"is_warning"`
Data interface{} `json:"data"`
}

type LinterErrorData struct {
Field string `json:"field"`
}

func (e *PipelineError) Error() string {
return fmt.Sprintf("[%s] %s", e.Type, e.Message)
}

func (e *PipelineError) GetLinterData() *LinterErrorData {
if e.Type != PipelineErrorTypeLinter {
return nil
}

if data, ok := e.Data.(*LinterErrorData); ok {
return data
}

return nil
}

func GetPipelineErrors(err error) []*PipelineError {
var pipelineErrors []*PipelineError
for _, _err := range multierr.Errors(err) {
var err *PipelineError
if errors.As(_err, &err) {
pipelineErrors = append(pipelineErrors, err)
} else {
pipelineErrors = append(pipelineErrors, &PipelineError{
Message: _err.Error(),
Type: PipelineErrorTypeGeneric,
})
}
}

return pipelineErrors
}

func HasBlockingErrors(err error) bool {
if err == nil {
return false
}

errs := GetPipelineErrors(err)

for _, err := range errs {
if !err.IsWarning {
return true
}
}

return false
}
Loading