Skip to content

Commit cd0ca64

Browse files
committed
add error handler
1 parent c008ccb commit cd0ca64

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

main.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ func writeSummary(stats *statistics) error {
126126
return nil
127127
}
128128

129+
func handleError(err error) {
130+
fmt.Fprintf(os.Stderr, "::error %s", err)
131+
os.Exit(1)
132+
}
133+
129134
func main() {
130135
printVersion := flag.Bool("version", false, "Print version")
131136
flag.Parse()
@@ -137,32 +142,28 @@ func main() {
137142

138143
input, err := parseInput()
139144
if err != nil {
140-
fmt.Fprintf(os.Stderr, "::error %s", err)
141-
os.Exit(1)
145+
handleError(err)
142146
}
143147

144148
args := buildArgs(input)
145149

146150
reviveVersion, err := getReviveVersion()
147151
if err != nil {
148-
fmt.Fprintf(os.Stderr, "::error %s", err)
149-
os.Exit(1)
152+
handleError(err)
150153
}
151154

152155
fmt.Printf("ACTION: %s\nREVIVE: %s\n", version, reviveVersion)
153156

154157
stats, code, err := runRevive(args)
155158
if err != nil {
156-
fmt.Fprintf(os.Stderr, "::error %s", err)
157-
os.Exit(1)
159+
handleError(err)
158160
}
159161

160162
fmt.Println("Successful run with", stats.String())
161163

162164
if v := os.Getenv("GITHUB_ACTIONS"); v == "true" {
163165
if err := writeSummary(stats); err != nil {
164-
fmt.Fprintf(os.Stderr, "::error %s", err)
165-
os.Exit(1)
166+
handleError(err)
166167
}
167168
} else {
168169
fmt.Println("Running outside of GitHub Actions, skipping summary")

0 commit comments

Comments
 (0)