fix: preserve cause chain when rewrapping name-collision error

This commit is contained in:
leave330
2026-07-08 17:53:18 +08:00
parent cb8d09d802
commit 78acceb910
2 changed files with 10 additions and 1 deletions

View File

@@ -82,7 +82,8 @@ var SlashCommandCreate = common.Shortcut{
if !runtime.Bool("force") {
p, _ := errs.ProblemOf(err)
rewrapped := errs.NewAPIError(p.Subtype, "slash command %q already exists", name).
WithHint("rerun with --force to update it, or use `lark-cli application +slash-command-update --command %q`", name)
WithHint("rerun with --force to update it, or use `lark-cli application +slash-command-update --command %q`", name).
WithCause(err)
if p.Code != 0 {
rewrapped = rewrapped.WithCode(p.Code)
}

View File

@@ -5,6 +5,7 @@ package application
import (
"encoding/json"
"errors"
"strings"
"testing"
@@ -103,6 +104,13 @@ func TestSlashCommandCreate_ConflictNoForce(t *testing.T) {
if !strings.Contains(p.Hint, "--force") || !strings.Contains(p.Hint, "+slash-command-update") {
t.Fatalf("hint must offer --force and update, got %q", p.Hint)
}
var apiErr *errs.APIError
if !errors.As(err, &apiErr) {
t.Fatalf("rewrapped error must be *errs.APIError, got %T", err)
}
if errors.Unwrap(apiErr) == nil {
t.Fatal("rewrapped conflict error must preserve the original cause via WithCause")
}
}
func TestSlashCommandCreate_ForceConvertsToUpdate(t *testing.T) {