Skip to content

feat(gorm): implement Translate for Spanner gRPC errors#244

Open
Gage-McGuire wants to merge 2 commits into
googleapis:mainfrom
Gage-McGuire:main
Open

feat(gorm): implement Translate for Spanner gRPC errors#244
Gage-McGuire wants to merge 2 commits into
googleapis:mainfrom
Gage-McGuire:main

Conversation

@Gage-McGuire

Copy link
Copy Markdown

Implementation of #243

Only added the mapping of AlreadyExists to gorm.ErrDuplicatedKey. There is a way to also add mappings for other error types but requires evaluating the desc of the returned errors from spanner. Which IMO could become fragile since Google states desc could be changed at anytime... (example below)

switch code {
    case codes.FailedPrecondition:
        if strings.Contains(msg, "Foreign key constraint") {
            return gorm.ErrForeignKeyViolated
        }
    case codes.OutOfRange:
        if strings.Contains(msg, "Check constraint") {
            return gorm.ErrCheckConstraintViolated
        }
    case codes.InvalidArgument:
        if strings.Contains(msg, "Unrecognized name") {
            return gorm.ErrInvalidField
        }
    }

@Gage-McGuire Gage-McGuire requested a review from a team as a code owner June 30, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant