{"record":{"id":"fe682a07a57b2230","repo":"go-kratos/kratos","slug":"repo-url-cannot-be-empty","errorCode":null,"errorMessage":"repo URL cannot be empty","messagePattern":"repo URL cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/kratos/internal/project/project.go","lineNumber":190,"sourceCode":"\t\t\thuh.NewSelect[string]().\n\t\t\t\tTitle(\"Select a template\").\n\t\t\t\tOptions(\n\t\t\t\t\thuh.NewOption(\"Service\", \"service\"),\n\t\t\t\t\thuh.NewOption(\"Admin\", \"admin\"),\n\t\t\t\t\thuh.NewOption(\"Custom (enter repo URL)\", \"custom\"),\n\t\t\t\t).\n\t\t\t\tValue(&choice),\n\t\t),\n\t\t// 2) Input group (only visible when choice == \"custom\")\n\t\thuh.NewGroup(\n\t\t\thuh.NewInput().\n\t\t\t\tTitle(\"Enter custom repository URL\").\n\t\t\t\tPlaceholder(\"https://github.com/owner/repo.git\").\n\t\t\t\tValue(&customURL).\n\t\t\t\tValidate(func(s string) error {\n\t\t\t\t\ts = strings.TrimSpace(s)\n\t\t\t\t\tif s == \"\" {\n\t\t\t\t\t\treturn fmt.Errorf(\"repo URL cannot be empty\")\n\t\t\t\t\t}\n\t\t\t\t\treturn nil\n\t\t\t\t}),\n\t\t).WithHideFunc(func() bool {\n\t\t\treturn choice != \"custom\"\n\t\t}),\n\t)\n\tif err := form.Run(); err != nil {\n\t\tpanic(err)\n\t}\n\tif choice == \"custom\" {\n\t\treturn strings.TrimSpace(customURL), nil\n\t}\n\treturn projects[choice], nil\n}\n","sourceCodeStart":172,"sourceCodeEnd":206,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/cmd/kratos/internal/project/project.go#L172-L206","documentation":"Inline validation in the kratos new interactive form: when the custom repository option is selected, the URL input rejects empty or whitespace-only submissions. The form cannot proceed until a non-empty URL is entered or a preset option is chosen instead.","triggerScenarios":"Selecting the custom repo choice in the new-project form and submitting with the URL input empty after strings.TrimSpace.","commonSituations":"User tries to skip the input; clipboard paste fails leaving the field blank; scripted runs hitting the interactive prompt unexpectedly.","solutions":["Type or paste a full git URL (e.g. https://github.com/owner/repo.git) and resubmit","Switch to a non-custom (preset) repository option instead"],"exampleFix":"# before\n? Select repo: custom\n? Enter custom repository URL: (empty) -> repo URL cannot be empty\n\n# after\n? Enter custom repository URL: https://github.com/owner/repo.git","handlingStrategy":"validation","validationCode":"u := strings.TrimSpace(customURL)\nif u == \"\" {\n    return errors.New(\"repo URL cannot be empty\")\n}\nif _, err := url.ParseRequestURI(u); err != nil {\n    return fmt.Errorf(\"invalid repo URL: %v\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default the custom URL field to a template repo you own","Validate git URLs before invoking the CLI in scripts (CI)","Prefer non-interactive flags in automation"],"tags":["cli","validation","user-input","forms"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}