openaec-foundation/frappe_claude_skill_package/frappe-errors-serverscripts
Claude Code and agent skill by openaec-foundation/frappe_claude_skill_package
- community
Checking that the SKILL.md file is still in the repository.
Use when debugging or preventing errors in Frappe Server Scripts. Prevents ImportError (the #1 error), NameError for restricted builtins, sandbox violations, doc_events not firing, wrong script type selection, SQL injection, permission denied in scheduled scripts, infinite loops, and API scripts not returning JSON. Covers error message mapping table. Keywords: server script error, ImportError, NameError, sandbox,, ImportError in server script, script not running, sandbox error, restricted function. restricted, frappe.throw, doc_events, scheduler, API script, SQL injection.
Install
npx vskill@latest install openaec-foundation/frappe_claude_skill_package/frappe-errors-serverscriptsSKILL.md
The same SKILL.md was published earlier as openaec-foundation/frappe_claude_skill_package/frappe-errors-serverscripts.
Server Script Errors — Diagnosis and Resolution
Cross-refs: frappe-syntax-serverscripts (syntax), frappe-impl-serverscripts (workflows), frappe-errors-clientscripts (client-side).
CRITICAL: Server Scripts Disabled by Default [v15+]
Starting from Frappe v15, Server Scripts are disabled by default. You MUST enable them:
On Frappe Cloud: Server Scripts are ONLY available on private benches, NOT on shared benches.
Error Diagnosis Flowchart
Error Message → Cause → Fix Table
| Error Message | Cause | Fix | |
|---|---|---|---|
ImportError: import not allowed | Any import statement in sandbox | Use frappe.utils, frappe.parse_json(), etc. | |
NameError: name 'dict' is not defined | Some Python builtins blocked by RestrictedPython | Use frappe._dict() or literal {} | |
SyntaxError: try/except not allowed | RestrictedPython blocks exception handling [v14-v15] | Use conditional checks (if/else) instead | |
SyntaxError: raise not allowed | RestrictedPython blocks raise | Use frappe.throw() | |
Script not executing | Wrong Script Type or Event selected | Verify type matches: Document Event, API, or Scheduler | |
doc is not defined | Using doc in API or Scheduler script (no document context) | doc is only available in Document Event scripts | |
PermissionError in Scheduler | Scheduler runs as Administrator but script accesses restricted resource | Use ignore_permissions=True where appropriate | |
Changes not saved in Scheduler | Missing frappe.db.commit() | ALWAYS call frappe.db.commit() in Scheduler scripts | |
API returns empty response | Forgot to set frappe.response["message"] | ALWAYS set frappe.response["message"] = result | |
Timeout / killed | Infinite loop or processing too many records | ALWAYS add limit to queries, ALWAYS use batch processing | |
ValidationError: qty is required | doc.save() called in Before Save (recursion) | NEVER call doc.save() in Before Save; just set values | |
SQL injection via string format | User input in SQL without escaping | ALWAYS use frappe.db.escape() or parameterized queries |
The #1 Error: ImportError
Every beginner hits this. The Server Script sandbox blocks ALL imports except json.
Available Sandbox API (Complete Reference)
| Category | Available Methods | |
|---|---|---|
| Document | frappe.get_doc(), frappe.new_doc(), frappe.get_last_doc(), frappe.get_cached_doc(), frappe.get_mapped_doc(), frappe.rename_doc(), frappe.delete_doc() | |
| Database | frappe.db.get_list(), frappe.db.get_all(), frappe.db.get_value(), frappe.db.get_single_value(), frappe.db.set_value(), frappe.db.exists(), frappe.db.sql(), frappe.db.commit(), frappe.db.rollback(), frappe.db.escape() | |
| Query Builder | frappe.qb (full query builder) | |
| HTTP | frappe.make_get_request(), frappe.make_post_request(), frappe.make_put_request() | |
| Utility | frappe.utils.* (all utility functions), frappe.parse_json(), frappe.as_json() | |
| User/Session | frappe.session.user, frappe.get_roles(), frappe.has_permission() | |
| Messages | frappe.throw(), frappe.msgprint(), frappe.log_error(), frappe.sendmail() | |
| Module | json (the ONLY importable module) |
Script Type Selection Errors
ALWAYS verify you selected the correct Script Type:
| Script Type | Trigger | Has doc? | Has frappe.form_dict? | Auto-commit? | |
|---|---|---|---|---|---|
| Document Event | DocType lifecycle (Before Save, After Save, etc.) | YES | NO | YES | |
| API | HTTP request to /api/method/{method_name} | NO | YES | YES | |
| Scheduler Event | Cron schedule | NO | NO | NO — MUST call frappe.db.commit() | |
| Permission Query | Every list query on the DocType | NO | NO (has user) | N/A |
Common Mistake: Wrong Event
Sandbox Workarounds
try/except Is Blocked: Use Conditional Checks
raise Is Blocked: Use frappe.throw()
frappe.throw() Exception Types for API Scripts
| Exception | HTTP Code | Use When | |
|---|---|---|---|
frappe.ValidationError | 417 | Input validation failure | |
frappe.PermissionError | 403 | Access denied | |
frappe.DoesNotExistError | 404 | Record not found | |
frappe.AuthenticationError | 401 | Not logged in | |
| (default, no exc) | 417 | General validation error |
Scheduler Script: Critical Mistakes
SQL Injection Prevention
ALWAYS / NEVER Rules
ALWAYS
- Use `frappe.utils.*` instead of Python imports — Only
jsonmodule is importable - Use `frappe.throw()` instead of `raise` —
raiseis blocked by sandbox - Use conditional checks instead of `try/except` — Exception handling is blocked [v14-v15]
- Call `frappe.db.commit()` in Scheduler scripts — Changes are NOT auto-committed
- Add `limit` to ALL queries in Scheduler scripts — Prevent memory exhaustion
- Set `frappe.response["message"]` in API scripts — Otherwise response is empty
- Use `frappe.db.escape()` for user input in SQL — Prevent SQL injection
- Log errors in Scheduler scripts with
frappe.log_error()— No user to see errors - Verify Script Type matches your intent — Document Event vs API vs Scheduler
NEVER
- NEVER use `import` statements (except
json) — Blocked by RestrictedPython - NEVER use `try/except` or `raise` — Blocked by sandbox [v14-v15]
- NEVER call `doc.save()` in Before Save — Causes infinite recursion
- NEVER use string formatting for SQL with user input — SQL injection risk
- NEVER process unlimited records in Scheduler — Always use
limit - NEVER assume `doc` exists in API/Scheduler scripts — Only available in Document Events
- NEVER forget `frappe.db.commit()` in Scheduler — All changes will be lost
Reference Files
| File | Contents | |
|---|---|---|
references/examples.md | Real error scenarios with diagnosis | |
references/anti-patterns.md | Common sandbox mistakes with fixes | |
references/patterns.md | Defensive error handling patterns by script type |
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/source/errors/frappe-errors-serverscripts/SKILL.md
Popularity
- Repository stars
- 88
- Repository forks
- 25
- 7-day trend score
- 22
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 28 Apr 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/openaec-foundation/frappe_claude_skill_package/frappe-errors-serverscripts)