error-pattern-safety
Error Pattern Safety Guidelines for Agentic Engines
Install
mkdir -p .claude/skills/error-pattern-safety && curl -L -o skill.zip "https://mcp.directory/api/skills/download/4366" && unzip -o skill.zip -d .claude/skills/error-pattern-safety && rm skill.zipInstalls to .claude/skills/error-pattern-safety
About this skill
Error Pattern Safety Guidelines
This document outlines the safety guidelines for error pattern regex in agentic engines to prevent infinite loops in JavaScript.
The Problem
When using regex patterns with the JavaScript global flag (/pattern/g), patterns that can match zero-width (empty strings) can cause infinite loops. This happens because:
- JavaScript's
regex.exec()with thegflag useslastIndexto track position - When a pattern matches zero-width,
lastIndexdoesn't advance - The same position is matched repeatedly, causing an infinite loop
Dangerous Pattern Examples
❌ NEVER USE THESE PATTERNS:
// Pure .* - matches everything including empty string at end
/.*/g
// Single character with * - matches zero or more (including zero)
/a*/g
// Patterns that can match empty string
/(x|y)*/g
Safe Pattern Examples
✅ ALWAYS USE PATTERNS LIKE THESE:
// Required prefix before .*
/error.*/gi
/error.*permission.*denied/gi
// Specific structure with required content
/\[(\d{4}-\d{2}-\d{2})\]\s+(ERROR):\s+(.+)/g
// Required characters throughout
/access denied.*user.*not authorized/gi
Pattern Safety Rules
-
Always require at least one character match
- Use
.+instead of.*when you need "something" - Ensure pattern has required prefix/suffix
- Use
-
Never use bare
.*as the entire pattern- Always combine with required text:
error.* - Never just
.*or.*?
- Always combine with required text:
-
Test patterns against empty string
const regex = /your-pattern/g; if (regex.test("")) { throw new Error("Pattern matches empty string - DANGEROUS!"); } -
Use specific anchors when possible
- Start:
^error.* - End:
.*error$ - Word boundaries:
\berror\b
- Start:
Validation Tests
All error patterns must pass these tests:
Go Tests (pkg/workflow/engine_error_patterns_infinite_loop_test.go)
// Test that pattern doesn't match empty string
func TestPatternSafety(t *testing.T) {
pattern := "your-pattern"
regex := regexp.MustCompile(pattern)
if regex.MatchString("") {
t.Error("Pattern matches empty string!")
}
}
JavaScript Tests (pkg/workflow/js/validate_errors.test.cjs)
test("should not match empty string", () => {
const regex = new RegExp("your-pattern", "g");
expect(regex.test("")).toBe(false);
});
Safety Mechanisms in validate_errors.cjs
The validate_errors.cjs script has built-in protections:
- Zero-width detection: Checks if
regex.lastIndexstops advancing - Iteration warning: Warns at 1000 iterations
- Hard limit: Stops at 10,000 iterations to prevent hang
// Safety check in validate_errors.cjs
if (regex.lastIndex === lastIndex) {
core.error(`Infinite loop detected! Pattern: ${pattern.pattern}`);
break;
}
Adding New Error Patterns
When adding new error patterns to engines:
-
Write the pattern with required content
{ Pattern: `(?i)error.*permission.*denied`, LevelGroup: 0, MessageGroup: 0, Description: "Permission denied error", } -
Test against empty string
- Run:
make test-unit - Checks:
TestAllEnginePatternsSafe
- Run:
-
Test with actual log samples
- Ensure it matches real errors
- Ensure it doesn't match informational text
-
Document the pattern
- Add clear description
- Note what it's designed to catch
Pattern Conversion: Go to JavaScript
Patterns are converted from Go to JavaScript:
// Go pattern (case-insensitive flag)
Pattern: `(?i)error.*permission.*denied`
// Converted to JavaScript
new RegExp("error.*permission.*denied", "gi")
The (?i) prefix is removed because JavaScript uses the i flag instead.
Examples from Current Codebase
✅ Safe Patterns
// Requires "error" prefix
Pattern: `(?i)error.*permission.*denied`
// Requires specific timestamp format
Pattern: `(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)\s+\[(ERROR)\]\s+(.+)`
// Requires "access denied" prefix
Pattern: `(?i)access denied.*user.*not authorized`
How to Fix Unsafe Patterns
If you find a pattern that matches empty string:
Before (unsafe):
Pattern: `.*error.*` // Can match empty at start/end
After (safe):
Pattern: `error.*` // Requires "error" at start
// OR
Pattern: `.*error.+` // Requires "error" and at least one char after
// OR
Pattern: `\berror\b.*` // Requires word "error"
Testing Checklist
Before committing pattern changes:
- Run
make test-unit - Check
TestAllEnginePatternsSafepasses - Check
TestErrorPatternsNoInfiniteLoopPotentialpasses - Run JavaScript tests:
cd pkg/workflow/js && npm test - Verify pattern matches intended error messages
- Verify pattern doesn't match informational text
References
- Go regex syntax: https://pkg.go.dev/regexp/syntax
- JavaScript regex: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
- Test files:
pkg/workflow/engine_error_patterns_infinite_loop_test.gopkg/workflow/js/validate_errors.test.cjspkg/workflow/error_pattern_tuning_test.go
More by githubnext
View all skills by githubnext →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
Related MCP Servers
Browse all serversSync Trello with Google Calendar easily. Fast, automated Trello workflows, card management & seamless Google Calendar in
Claude Historian is a free AI search engine offering advanced search, file context, and solution discovery in Claude Cod
Claude Historian: AI-powered search for Claude Code conversations—find files, errors, context, and sessions via JSONL pa
WSL Exec enables secure command execution in WSL with advanced safety features like path validation, timeouts, and robus
Access FDA drug info, faers data, and adverse event reports with OpenFDA’s robust tools for faers, vaers, and NDC valida
Validate Oh My Posh theme configurations quickly and reliably against the official schema to ensure error-free prompts a
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.