Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/cmdutil/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func (f *Factory) CheckIdentity(as core.Identity, supported []string) error {
list := strings.Join(supported, ", ")
if f.IdentityAutoDetected {
return output.ErrValidation(
"resolved identity %q (via auto-detect or default-as) is not supported, this command only supports: %s\nhint: use --as %s",
as, list, supported[0])
"this command requires %s identity, but no user login was found (auto-detected as %s)\nhint: run `lark-cli auth login` first, then retry",
list, as)
Comment on lines +130 to +131
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Auto-detected mismatch message is overly specific and can be wrong

Line 130 hardcodes a user-login diagnosis for every auto-detected mismatch. For bot-only (or other non-user) supported identities, this is misleading.

Proposed fix
 	list := strings.Join(supported, ", ")
 	if f.IdentityAutoDetected {
-		return output.ErrValidation(
-			"this command requires %s identity, but no user login was found (auto-detected as %s)\nhint: run `lark-cli auth login` first, then retry",
-			list, as)
+		if len(supported) == 1 && supported[0] == string(core.AsUser) {
+			return output.ErrValidation(
+				"this command requires user identity, but no user login was found (auto-detected as %s)\nhint: run `lark-cli auth login` first, then retry",
+				as,
+			)
+		}
+		return output.ErrValidation(
+			"auto-detected identity %s is not supported, this command only supports: %s",
+			as, list,
+		)
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/cmdutil/factory.go` around lines 130 - 131, The error message that
constructs the mismatch string in factory.go hardcodes "user login" which is
incorrect for non-user identities; update the formatted string used where the
code currently builds: "this command requires %s identity, but no user login was
found (auto-detected as %s)\nhint: run `lark-cli auth login` first, then retry"
to a neutral form like "this command requires %s identity, but no login was
found (auto-detected as %s)\nhint: run `lark-cli auth login` first, then retry"
(or conditionally vary the phrase only when list indicates a user identity);
change the message construction at that location to use the variable names
already present (list and as) and avoid hardcoding "user".

}
return fmt.Errorf("--as %s is not supported, this command only supports: %s", as, list)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/cmdutil/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ func TestCheckIdentity_Unsupported_AutoDetected(t *testing.T) {
f, _, _, _ := TestFactory(t, &core.CliConfig{AppID: "a", AppSecret: "s"})
f.IdentityAutoDetected = true

err := f.CheckIdentity(core.AsUser, []string{"bot"})
err := f.CheckIdentity(core.AsBot, []string{"user"})
if err == nil {
t.Fatal("expected error")
}
if !strings.Contains(err.Error(), "resolved identity") {
t.Errorf("expected 'resolved identity' in error, got: %v", err)
if !strings.Contains(err.Error(), "requires user identity") {
t.Errorf("expected 'requires user identity' in error, got: %v", err)
}
if !strings.Contains(err.Error(), "hint: use --as bot") {
t.Errorf("expected hint in error, got: %v", err)
if !strings.Contains(err.Error(), "auth login") {
t.Errorf("expected 'auth login' hint in error, got: %v", err)
}
}

Expand Down
Loading