fix: tighten target error hint coverage

This commit is contained in:
Peter Steinberger
2026-03-14 01:00:45 +00:00
parent 25f458a907
commit 0146345b88
2 changed files with 13 additions and 2 deletions

View File

@@ -19,6 +19,16 @@ describe("target error helpers", () => {
);
});
it("treats blank hints the same as no hint", () => {
expect(missingTargetMessage("Slack", " ")).toBe("Delivering to Slack requires target");
expect(ambiguousTargetMessage("Discord", "general", " ")).toBe(
'Ambiguous target "general" for Discord. Provide a unique name or an explicit id.',
);
expect(unknownTargetMessage("Discord", "general", " ")).toBe(
'Unknown target "general" for Discord.',
);
});
it("formats ambiguous and unknown target messages with labeled hints", () => {
expect(ambiguousTargetMessage("Discord", "general")).toBe(
'Ambiguous target "general" for Discord. Provide a unique name or an explicit id.',

View File

@@ -23,8 +23,9 @@ export function unknownTargetError(provider: string, raw: string, hint?: string)
}
function formatTargetHint(hint?: string, withLabel = false): string {
if (!hint) {
const normalized = hint?.trim();
if (!normalized) {
return "";
}
return withLabel ? ` Hint: ${hint}` : ` ${hint}`;
return withLabel ? ` Hint: ${normalized}` : ` ${normalized}`;
}