Skip to content

Commit d4c1670

Browse files
committed
fix(project): slugify name in 409 conflict hint
The view command hint on 409 used the raw name ('My Cool App') instead of the expected slug ('my-cool-app'), pointing to a non-existent target.
1 parent 8766e4c commit d4c1670

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/commands/project/create.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ const PLATFORMS = [
5959
"elixir",
6060
] as const;
6161

62+
/**
63+
* Convert a project name to its expected Sentry slug.
64+
* Sentry slugs are lowercase, with non-alphanumeric runs replaced by hyphens.
65+
*
66+
* @example slugify("My Cool App") // "my-cool-app"
67+
* @example slugify("my-app") // "my-app"
68+
*/
69+
function slugify(name: string): string {
70+
return name
71+
.toLowerCase()
72+
.replace(/[^a-z0-9]+/g, "-")
73+
.replace(/^-|-$/g, "");
74+
}
75+
6276
/** Check whether an API error is about an invalid platform value */
6377
function isPlatformError(error: ApiError): boolean {
6478
const detail = error.detail ?? error.message;
@@ -150,9 +164,10 @@ async function createProjectWithErrors(
150164
} catch (error) {
151165
if (error instanceof ApiError) {
152166
if (error.status === 409) {
167+
const slug = slugify(name);
153168
throw new CliError(
154169
`A project named '${name}' already exists in ${orgSlug}.\n\n` +
155-
`View it: sentry project view ${orgSlug}/${name}`
170+
`View it: sentry project view ${orgSlug}/${slug}`
156171
);
157172
}
158173
if (error.status === 400 && isPlatformError(error)) {

0 commit comments

Comments
 (0)