Skip to content

Fix duplicate-key DB error handling to support all drivers (not only SQLite) #1994

@coderabbitai

Description

@coderabbitai

Summary

Duplicate-key errors from the repository layer are currently only detected for SQLite via isSQLiteUniqueConstraint. When running against other supported databases (e.g. PostgreSQL), a duplicate create operation surfaces as a generic failure instead of mapping to the appropriate sentinel error (e.g. ErrWebBrokerAPIExists, ErrWebSubAPIExists, etc.).

A cross-driver helper (e.g. isDuplicateKeyError) should be introduced that covers driver-specific error codes/messages (PostgreSQL code 23505, MySQL errno 1062, SQLite unique constraint, etc.) and used at all affected call sites.

Affected files

  • platform-api/src/internal/service/webbroker_api.go (line 154)
  • platform-api/src/internal/service/websub_api.go (line 153)
  • platform-api/src/internal/service/mcp.go (line 136)
  • platform-api/src/internal/service/llm.go (lines 148, 352, 643)

Note: gateway/gateway-controller/pkg/storage/factory.go already uses an abstracted isUniqueViolation function-field pattern, which can serve as a reference for the fix.

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions