Skip to content

fix(integration): NewIntegrationManager 改为返回 error,不再 panic#247

Merged
aby913 merged 1 commit intomainfrom
cursor/fix-integration-manager-panic
May 6, 2026
Merged

fix(integration): NewIntegrationManager 改为返回 error,不再 panic#247
aby913 merged 1 commit intomainfrom
cursor/fix-integration-manager-panic

Conversation

@pengpeng
Copy link
Copy Markdown
Member

@pengpeng pengpeng commented May 5, 2026

概要

`pkg/integration/integration.go` 的 `NewIntegrationManager` 在三处 K8s client 构造失败时直接 `panic(err)`:

```go
config, err := ctrl.GetConfig(); if err != nil { panic(err) }
client, err := dynamic.NewForConfig(config); if err != nil { panic(err) }
kubeClient, err := kubernetes.NewForConfig(); if err != nil { panic(err) }
```

启动期 API server 短暂抖动就会让进程吐 panic stack 而不是一行清晰的失败原因。库代码 panic 也让上层无法选择是 fatal 还是降级。

改动

  • `NewIntegrationManager() error`:三处错误改成 `fmt.Errorf(": %w", err)` 返回;
  • `cmd/backend/app/root.go`:调用方改为 `if err := integration.NewIntegrationManager(); err != nil { klog.Fatalf(...) }`。

观感和原来一致(启动失败就退出),但日志里看到的是 "init integration manager: ..." 而非 panic backtrace。

验证方式

  • `go build ./pkg/integration/ ./cmd/backend/app/` 通过。
  • 手工:把 `KUBECONFIG` 指向一个不存在的文件启动;进程退出,最后一行日志是 "init integration manager: ctrl.GetConfig: ..."。

Made with Cursor

NewIntegrationManager called panic(err) on three different K8s
client construction failures. Any transient API-server issue at
startup would dump a panic stack into the log instead of a clear
single-line failure.

Return an error and let cmd/backend/app/root.go decide. The caller
now does klog.Fatal with a clean "init integration manager: <err>"
message - same observable outcome (process exits) but no library
panic in the logs.

Co-authored-by: Cursor <cursoragent@cursor.com>
@aby913 aby913 merged commit 253df1c into main May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants