Browse Source
Merge pull request #434 from cursor-home/master
fix: Improve panic recovery mechanism in main function
pull/483/head
v0.0.144
煎饼果子卷鲨鱼辣椒@86
2 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
11 additions and
13 deletions
-
cmd/cursor-id-modifier/main.go
|
@ -11,13 +11,13 @@ import ( |
|
|
"runtime/debug" |
|
|
"runtime/debug" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus" |
|
|
|
|
|
|
|
|
"github.com/yuaotian/go-cursor-help/internal/config" |
|
|
"github.com/yuaotian/go-cursor-help/internal/config" |
|
|
"github.com/yuaotian/go-cursor-help/internal/lang" |
|
|
"github.com/yuaotian/go-cursor-help/internal/lang" |
|
|
"github.com/yuaotian/go-cursor-help/internal/process" |
|
|
"github.com/yuaotian/go-cursor-help/internal/process" |
|
|
"github.com/yuaotian/go-cursor-help/internal/ui" |
|
|
"github.com/yuaotian/go-cursor-help/internal/ui" |
|
|
"github.com/yuaotian/go-cursor-help/pkg/idgen" |
|
|
"github.com/yuaotian/go-cursor-help/pkg/idgen" |
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus" |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// Global variables
|
|
|
// Global variables
|
|
@ -29,7 +29,15 @@ var ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
setupErrorRecovery() |
|
|
|
|
|
|
|
|
// Place defer at the beginning of main to ensure it can catch panics from all subsequent function calls
|
|
|
|
|
|
defer func() { |
|
|
|
|
|
if r := recover(); r != nil { |
|
|
|
|
|
log.Errorf("Panic recovered: %v\n", r) |
|
|
|
|
|
debug.PrintStack() |
|
|
|
|
|
waitExit() |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
handleFlags() |
|
|
handleFlags() |
|
|
setupLogger() |
|
|
setupLogger() |
|
|
|
|
|
|
|
@ -73,16 +81,6 @@ func main() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func setupErrorRecovery() { |
|
|
|
|
|
defer func() { |
|
|
|
|
|
if r := recover(); r != nil { |
|
|
|
|
|
log.Errorf("Panic recovered: %v\n", r) |
|
|
|
|
|
debug.PrintStack() |
|
|
|
|
|
waitExit() |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func handleFlags() { |
|
|
func handleFlags() { |
|
|
flag.Parse() |
|
|
flag.Parse() |
|
|
if *showVersion { |
|
|
if *showVersion { |
|
|