Is there a more advance way to handle Go Entgo postgreSQL error handling?


So I’m developing a API using Go together with ORM package Entgo and Postgres. Is there a way to handle the errors same or similar way as they are solved in pg package where I have all needed information why query failed?

All I found in ent go are this methods but they only return bool


It would be great to have something similar like pg.Error:

type Error struct {
Severity         string
Code             ErrorCode
Message          string
Detail           string
Hint             string
Position         string
InternalPosition string
InternalQuery    string
Where            string
Schema           string
Table            string
Column           string
DataTypeName     string
Constraint       string
File             string
Line             string
Routine          string


So I asked this same question on package repo and this is the answer I got from repo Maintainer.

Ent wraps or returns the underlying driver errors. So, you can either use type-assertion or errors.Is/errors.As helpers to extract these types.

See examples in our integration-test:

Answered By – Petar Arandjic

Answer Checked By – Dawn Plyler (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.