Skip to content

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Jan 9, 2026

Summary

Reduces verbosity of error output when migrations fail with many pgpm_migrate.deploy calls. Previously, a failed deployment with 1600+ migrations would output 1600+ lines of query history. Now, consecutive identical queries are collapsed into a summary showing the range, count, and first/last change names.

Key changes:

  • Smart collapsing of consecutive identical queries (e.g., "2-57. CALL pgpm_migrate.deploy... (56 calls)")
  • For deploy calls, shows first and last change names for context
  • Configurable via environment variables:
    • PGPM_ERROR_QUERY_HISTORY_LIMIT (default: 30 queries)
    • PGPM_ERROR_MAX_LENGTH (default: 10000 chars)
    • PGPM_ERROR_VERBOSE=true to disable all limiting
  • Added comprehensive test suite (11 tests including snapshot test for exact output format)
  • Updated README with configuration documentation
  • Environment variables follow centralized pattern via @pgpmjs/env and @pgpmjs/types

Review & Testing Checklist for Human

  • Test with a real failed deployment - Trigger a migration failure with many deploy calls and verify the output is readable and still contains useful debugging info
  • Verify env vars work - Test that PGPM_ERROR_VERBOSE=true shows full output, and that the limit vars work as expected
  • Check edge cases - What happens when the error occurs on the first query? When there's only one query? When all queries are different?
  • Verify code organization - Confirm the new errors.ts file is properly separated from transaction.ts and imports work correctly

Recommended test plan:

  1. Run the new tests: cd pgpm/core && pnpm test -- error-output-formatting
  2. Manually trigger a deployment failure with many migrations and verify the collapsed output
  3. Set PGPM_ERROR_VERBOSE=true and verify full output is shown

Notes

  • The collapsing is generic (works for any repetitive query pattern), but has special handling for pgpm_migrate.deploy to extract change names from params
  • Environment variables are read at module load time via getErrorOutputConfig(), so changes require process restart
  • The extractDeployChangeName function assumes params[1] is the change name - this matches the current pgpm_migrate.deploy signature

Updates since last revision

  • Fixed test assertions to match actual output format (collapsed groups include First/Last context lines)
  • Added additional integration test for truncation behavior when exceeding query limit
  • Refactored to use centralized env var parsing: added ErrorOutputOptions interface to @pgpmjs/types, added errorOutput to PgpmOptions and pgpmDefaults, added env var parsing in @pgpmjs/env, updated transaction.ts to use getErrorOutputConfig() instead of direct process.env access
  • Fixed snapshot test in pgpm/env to include the new errorOutput field in getEnvVars() return value
  • Code organization refactor: Extracted all error formatting logic (~200 lines) into new errors.ts file, keeping transaction.ts focused on transaction lifecycle. Functions are re-exported from transaction.ts for backward compatibility.
  • Added snapshot test: New snapshot test captures the exact error output format for a realistic deployment scenario, serving as documentation and regression protection

Link to Devin run: https://app.devin.ai/sessions/c634626524714b3596c4d506d7f94a9a
Requested by: Dan Lynch (@pyramation)

- Add smart collapsing of consecutive identical queries in error output
- For pgpm_migrate.deploy calls, show first/last change names for context
- Add PGPM_ERROR_QUERY_HISTORY_LIMIT env var (default: 30 queries)
- Add PGPM_ERROR_MAX_LENGTH env var (default: 10000 chars)
- Add PGPM_ERROR_VERBOSE env var to disable all limiting
- Add tests for error output formatting
- Update README with configuration documentation
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

…pgpmjs/types

- Add ErrorOutputOptions interface to @pgpmjs/types with queryHistoryLimit, maxLength, verbose
- Add errorOutput to PgpmOptions interface and pgpmDefaults
- Add PGPM_ERROR_* env var parsing in @pgpmjs/env getEnvVars()
- Update transaction.ts to use centralized config instead of direct process.env access
@pyramation pyramation merged commit 9a5d081 into main Jan 9, 2026
36 checks passed
@pyramation pyramation deleted the devin/1767966706-smart-error-output branch January 9, 2026 17:11
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.

2 participants