forked from cloudspannerecosystem/wrench
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
50 lines (41 loc) · 1.02 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"errors"
"fmt"
"os"
"github.com/mercari/wrench/cmd"
"github.com/mercari/wrench/pkg/spanner"
)
func main() {
execute()
}
func execute() {
handleError(cmd.Execute())
}
func handleError(err error) {
if err != nil {
fmt.Fprint(os.Stderr, (fmt.Sprintf("%s\n\t%s\n", err.Error(), errorDetails(err))))
os.Exit(1)
}
}
func errorDetails(err error) string {
var se *spanner.Error
if errors.As(err, &se) {
switch se.Code {
case spanner.ErrorCodeCreateClient:
return fmt.Sprintf("Failed to connect to Cloud Spanner, %s", se.Error())
case spanner.ErrorCodeExecuteMigrations, spanner.ErrorCodeMigrationVersionDirty:
return fmt.Sprintf("Failed to execute migration, %s", se.Error())
default:
return fmt.Sprintf("Failed to execute the operation to Cloud Spanner, %s", se.Error())
}
}
var pe *os.PathError
if errors.As(err, &pe) {
return fmt.Sprintf("Invalid file path, %s", pe.Error())
}
if err := errors.Unwrap(err); err != nil {
return err.Error()
}
return "Unknown error..."
}