{"record":{"id":"39fcf1bedd81ea8d","repo":"wavetermdev/waveterm","slug":"invalid-new-app-name-w","errorCode":null,"errorMessage":"invalid new app name: %w","messagePattern":"invalid new app name: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/waveappstore/waveappstore.go","lineNumber":656,"sourceCode":"\treturn true, nil\n}\n\n// RenameLocalApp renames a local app by renaming its directories in both the local and draft namespaces.\n// It takes the current app name and the new app name (without namespace prefixes).\n// Both local/[appName] and draft/[appName] will be renamed if they exist.\n// Returns an error if the app doesn't exist in either namespace, if the new name is invalid,\n// or if the new name conflicts with an existing app.\nfunc RenameLocalApp(appName string, newAppName string) error {\n\t// Validate the old app name by constructing a valid appId\n\toldLocalAppId := MakeAppId(AppNSLocal, appName)\n\tif err := ValidateAppId(oldLocalAppId); err != nil {\n\t\treturn fmt.Errorf(\"invalid app name: %w\", err)\n\t}\n\n\t// Validate the new app name by constructing a valid appId\n\tnewLocalAppId := MakeAppId(AppNSLocal, newAppName)\n\tif err := ValidateAppId(newLocalAppId); err != nil {\n\t\treturn fmt.Errorf(\"invalid new app name: %w\", err)\n\t}\n\n\thomeDir := wavebase.GetHomeDir()\n\twaveappsDir := filepath.Join(homeDir, \"waveapps\")\n\n\toldLocalDir := filepath.Join(waveappsDir, AppNSLocal, appName)\n\tnewLocalDir := filepath.Join(waveappsDir, AppNSLocal, newAppName)\n\toldDraftDir := filepath.Join(waveappsDir, AppNSDraft, appName)\n\tnewDraftDir := filepath.Join(waveappsDir, AppNSDraft, newAppName)\n\n\t// Check if at least one of the apps exists\n\tlocalExists := false\n\tdraftExists := false\n\tif _, err := os.Stat(oldLocalDir); err == nil {\n\t\tlocalExists = true\n\t} else if !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"failed to check local app: %w\", err)\n\t}","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/waveappstore/waveappstore.go#L638-L674","documentation":"RenameLocalApp validates the NEW app name the same way as the old one, wrapping ValidateAppId failures as \"invalid new app name: %w\". The rename is refused before any directory is moved so the destination path is guaranteed well-formed.","triggerScenarios":"Calling RenameLocalApp(oldName, newName) where newName is empty, contains illegal characters, includes a namespace prefix, or otherwise fails ValidateAppId.","commonSituations":"User-typed new names with spaces or slashes, accidentally passing the full target appId instead of the name, empty newName from an unset variable or empty input field.","solutions":["Ensure the second argument is a bare, valid app name (no namespace prefix or invalid characters)","Trim whitespace and reject empty strings before calling","Pre-validate with ValidateAppId(MakeAppId(AppNSLocal, newName)) to see the wrapped cause"],"exampleFix":"// before\nRenameLocalApp(\"myapp\", \"\")\n// after\nnewName := strings.TrimSpace(input)\nif newName != \"\" { err := RenameLocalApp(\"myapp\", newName) }","handlingStrategy":"validation","validationCode":"func validNewName(name string) error {\n    if name == \"\" { return fmt.Errorf(\"new app name required\") }\n    _, err := waveappstore.ValidateAppId(waveappstore.MakeAppId(waveappstore.AppNSLocal, name))\n    return err\n}","typeGuard":"func isBareAppName(s string) bool {\n    return s != \"\" && !strings.Contains(s, \":\") && strings.TrimSpace(s) == s\n}","tryCatchPattern":"if err := waveappstore.RenameLocalApp(oldName, newName); err != nil {\n    if strings.Contains(err.Error(), \"invalid new app name\") {\n        return fmt.Errorf(\"choose a different new name: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate user-entered new names at input time, before calling RenameLocalApp","Never pass a full appId as the newName argument","Reject empty strings and illegal characters (spaces, slashes) in UI code"],"tags":["go","validation","rename","waveappstore"],"backgroundTag":"invalid-app-name","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}