MCPcopy
hub / github.com/rilldata/rill / parseErr

Function parseErr

admin/database/postgres/postgres.go:3975–4027  ·  view source on GitHub ↗
(target string, err error)

Source from the content-addressed store, hash-verified

3973}
3974
3975func parseErr(target string, err error) error {
3976 if err == nil {
3977 return nil
3978 }
3979 if errors.Is(err, sql.ErrNoRows) {
3980 if target == "" {
3981 return database.ErrNotFound
3982 }
3983 return database.NewNotFoundError(fmt.Sprintf("%s not found", target))
3984 }
3985 var pgerr *pgconn.PgError
3986 if !errors.As(err, &pgerr) {
3987 return err
3988 }
3989 if pgerr.Code == "23505" { // unique_violation
3990 switch pgerr.ConstraintName {
3991 case "orgs_name_idx":
3992 return database.NewNotUniqueError("an org with that name already exists")
3993 case "projects_name_idx":
3994 return database.NewNotUniqueError("a project with that name already exists in the org")
3995 case "users_email_idx":
3996 return database.NewNotUniqueError("a user with that email already exists")
3997 case "usergroups_name_idx":
3998 return database.NewNotUniqueError("a usergroup with that name already exists in the org")
3999 case "usergroups_users_pkey":
4000 return database.NewNotUniqueError("user is already a member of the usergroup")
4001 case "users_orgs_roles_pkey":
4002 return database.NewNotUniqueError("user is already a member of the org")
4003 case "users_projects_roles_pkey":
4004 return database.NewNotUniqueError("user is already a member of the project")
4005 case "usergroups_orgs_roles_pkey":
4006 return database.NewNotUniqueError("usergroup is already a member of the org")
4007 case "usergroups_projects_roles_pkey":
4008 return database.NewNotUniqueError("usergroup is already a member of the project")
4009 case "org_invites_email_org_idx":
4010 return database.NewNotUniqueError("email has already been invited to the org")
4011 case "project_invites_email_project_idx":
4012 return database.NewNotUniqueError("email has already been invited to the project")
4013 case "orgs_autoinvite_domains_org_id_domain_idx":
4014 return database.NewNotUniqueError("domain has already been added for the org")
4015 case "service_name_idx":
4016 return database.NewNotUniqueError("a service with that name already exists in the org")
4017 case "virtual_files_pkey":
4018 return database.NewNotUniqueError("a virtual file already exists at that path")
4019 default:
4020 if target == "" {
4021 return database.ErrNotUnique
4022 }
4023 return database.NewNotUniqueError(fmt.Sprintf("%s already exists", target))
4024 }
4025 }
4026 return err
4027}
4028
4029// encrypts plaintext using AES-GCM with the given key and returns the base64 encoded ciphertext
4030func encrypt(plaintext, key []byte) ([]byte, error) {

Calls 2

NewNotFoundErrorFunction · 0.92
NewNotUniqueErrorFunction · 0.92

Tested by

no test coverage detected