error-handling

Standardize PostgreSQL backend error reporting with ereport, elog, and PG_TRY/PG_CATCH blocks.

Updated Jun 1, 2026
One-click install
npx skills add https://github.com/matejformanek/postgres-claude --skill error-handling-matejformanek
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/matejformanek/postgres-claude/tree/main/.claude/skills/error-handling
Command: npx skills add https://github.com/matejformanek/postgres-claude --skill error-handling-matejformanek

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill eliminates common pitfalls in PostgreSQL backend development, such as incorrect error severity levels, improper SQLSTATE usage, and memory leaks caused by unsafe longjmp handling.

Core Features & Use Cases

  • Standardized Reporting: Provides authoritative guidance on choosing between ereport and elog, selecting appropriate SQLSTATE codes, and formatting error messages for gettext compatibility.
  • Safety Guardrails: Offers strict rules for PG_TRY/PG_CATCH blocks and resource management to prevent transaction abort failures and memory corruption.
  • Use Case: When implementing a new backend function, use this skill to ensure your error handling correctly manages system resources and follows the established PostgreSQL coding conventions for user-facing messages.

Quick Start

Use the error-handling skill to review the ereport call in the current function for correct SQLSTATE usage and proper message formatting.

Frequently Asked Questions about error-handling

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

FAQPage Schema
How do I use ereport correctly for PostgreSQL backend error reporting?

To use ereport correctly for PostgreSQL backend error reporting, you must enforce proper severity levels, select appropriate SQLSTATE codes, and format messages for gettext compatibility. This ensures transaction-safe logging and prevents system resource leaks during longjmp handling.

What is the difference between ereport and elog in PostgreSQL C source?

The difference between ereport and elog in PostgreSQL C source lies in their use cases: ereport is for user-facing messages requiring SQLSTATE codes and gettext formatting, while elog is typically for internal logging. Correct selection prevents transaction abort failures and memory corruption.

How do I prevent memory leaks in PostgreSQL PG_TRY/PG_CATCH blocks?

To prevent memory leaks in PostgreSQL PG_TRY/PG_CATCH blocks, you must follow strict resource management and memory context rules. Safe handling prevents memory corruption and transaction abort failures caused by unsafe longjmp jumps during backend error reporting.

Does PostgreSQL backend development require specific error handling idioms?

PostgreSQL backend development requires specific error handling idioms including adherence to internal coding conventions for memory context management, correct SQLSTATE selection, and standardized message formatting to ensure transaction safety and prevent system resource mismanagement.

Why does my PostgreSQL ereport call cause a transaction abort failure?

Your PostgreSQL ereport call might cause a transaction abort failure due to improper error severity levels, unsafe longjmp handling, or incorrect memory context management. Enforcing correct PG_TRY/PG_CATCH blocks and resource cleanup rules resolves this.