gorm-error-handling

Detect and manage GORM database errors with TranslateError and errors.Is checks.

Updated Apr 4, 2026
One-click install
npx skills add https://github.com/liurida/gorm-development-skill --skill gorm-error-handling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gorm-error-handling
Source: https://github.com/liurida/gorm-development-skill/tree/main/error_handling
Command: npx skills add https://github.com/liurida/gorm-development-skill --skill gorm-error-handling

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

GORM operations often return errors that, if not handled correctly, can cause crashes, data corruption, or silent failures, making debugging and reliability difficult.

Core Features & Use Cases

  • Unified Error Types: Standardized error constants like ErrRecordNotFound, ErrDuplicatedKey, and transaction errors.
  • TranslateError Support: Enables database‑agnostic error handling across MySQL, PostgreSQL, SQLite, and SQL Server.
  • Practical Patterns: Service‑layer wrappers, transaction rollback handling, and row‑affected checks for CRUD operations.
  • Use Case Example: In a Go microservice, use this skill to detect duplicate key violations during user creation and return a friendly “user already exists” message.

Quick Start

Invoke the skill with a request to check for errors after a GORM operation and receive a summarized handling strategy.

Frequently Asked Questions about gorm-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle GORM errors in Go applications?

GORM errors in Go applications are handled by enabling TranslateError and using errors.Is checks to detect standardized constants like ErrRecordNotFound and ErrDuplicatedKey. This approach prevents crashes and silent failures during CRUD actions and transactions.

How do I detect duplicate key violations in GORM?

To detect duplicate key violations in GORM, enable TranslateError and check errors.Is against the ErrDuplicatedKey constant. This database-agnostic method works across MySQL, PostgreSQL, SQLite, and SQL Server to return friendly messages during operations like user creation.

Does GORM TranslateError work across different database drivers?

Yes, GORM TranslateError works across different database drivers by translating database-specific errors into standardized constants. It supports MySQL, PostgreSQL, SQLite, and SQL Server, enabling database-agnostic error handling for robust constraint management.

What is the best way to manage transaction rollbacks in GORM?

The best way to manage transaction rollbacks in GORM is by applying practical service-layer wrappers and row-affected checks. This ensures robust error handling standards are met and prevents data corruption when transaction operations fail.

Why does my GORM record not found error cause a silent failure?

GORM record not found errors cause silent failures when TranslateError is not enabled and errors.Is checks are omitted. Proper error handling requires checking standardized constants like ErrRecordNotFound to satisfy robust application standards and prevent silent data issues.