error-pattern-safety
Security standards for managing error patterns in agentic AI systems.
Install
mkdir -p .claude/skills/error-pattern-safety && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/4366" && unzip -o skill.zip -d .claude/skills/error-pattern-safety && rm skill.zipInstalls to .claude/skills/error-pattern-safety
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Apply safe error-pattern matching rules for agentic engines.Key capabilities
- →Validate regex patterns for infinite loops
- →Enforce safe pattern matching rules
- →Test patterns against empty strings
- →Convert Go regex to JavaScript RegExp
How it works
It enforces safety rules that prevent zero-width matches in JavaScript regex, which otherwise cause infinite loops during execution.
Inputs & outputs
When to use error-pattern-safety
- →Establishing security standards for agent error handling
- →Auditing agent logging behavior
- →Preventing information leakage in error traces
About this skill
Error Pattern Safety Guidelines
Use these regex safety rules in agentic engines to prevent JavaScript infinite loops.
The Problem
With the JavaScript global flag (/pattern/g), zero-width matches can cause infinite loops 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
When not to use it
- →When using patterns that match empty strings without required content
Limitations
- →Requires adherence to specific regex safety rules
- →Limited to patterns compatible with the validation script
How it compares
It provides automated validation and testing protocols for regex safety, whereas manual review often misses edge cases like empty string matches.
Compared to similar skills
error-pattern-safety side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| error-pattern-safety (this skill) | 1 | 3mo | Review | Intermediate |
| reverse-engineering-tools | 73 | 3mo | No flags | Advanced |
| game-hacking-techniques | 42 | 2mo | No flags | Advanced |
| solidity-security | 15 | 2mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by githubnext
View all by githubnext →You might also like
reverse-engineering-tools
gmh5225
Guide for reverse engineering tools and techniques used in game security research. Use this skill when working with debuggers, disassemblers, memory analysis tools, binary analysis, or decompilers for game security research.
game-hacking-techniques
gmh5225
Guide for game hacking techniques and cheat development. Use this skill when researching memory manipulation, code injection, ESP/aimbot development, overlay rendering, or game exploitation methodologies.
solidity-security
wshobson
Master smart contract security best practices to prevent common vulnerabilities and implement secure Solidity patterns. Use when writing smart contracts, auditing existing contracts, or implementing security measures for blockchain applications.
1password
openclaw
Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.
senior-security
davila7
Comprehensive security engineering skill for application security, penetration testing, security architecture, and compliance auditing. Includes security assessment tools, threat modeling, crypto implementation, and security automation. Use when designing security architecture, conducting penetration tests, implementing cryptography, or performing security audits.
ghidra
mitsuhiko
Reverse engineer binaries using Ghidra's headless analyzer. Decompile executables, extract functions, strings, symbols, and analyze call graphs without GUI.