agentleFS
jyjeannejyjeanne/dita-skills/error-handling/SKILL.md

error-handling

Skill2 starsChanged 6 months agoMITView on GitHub

Reference skill for pydita's error recording and reporting model. Use this skill when you need to understand how errors are accumulated in the shared errors dict, work with ErrorRecord and SEVERITY, filter errors by severity level, or produce a formatted error report using reportErrors(). Covers DitaContext.recordError() and Logger/ConsoleLogger helpers.

80 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use convention-learner, caching and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • codewithmukeshSkill

    convention-learner

    Detects and enforces project-specific coding conventions by analyzing existing codebase patterns. Learns naming conventions, folder structure, test organization, and coding style from the existing code. Load when: "conventions", "coding standards", "project patterns", "enforce style", "detect patterns", "learn conventions", "code consistency".

    Also in 3 projects that use this

  • wpankSkill

    caching

    Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.

    Also in 6 projects that use this

  • diego-tobalinaSkill

    logging

    Logging best practices for Java (SLF4J/Logback) and Node.js (Winston/Pino). Use for structured logging, log levels, and avoiding sensitive data exposure.

    Also in 12 projects that use this

  • codewithmukeshSkill

    opentelemetry

    OpenTelemetry observability for .NET 10 applications. Covers traces, metrics, and logs using the OpenTelemetry SDK with OTLP export. Includes custom ActivitySource, IMeterFactory metrics, resource configuration, and Aspire Dashboard integration. Load this skill when setting up distributed tracing, custom metrics, OTLP export, or when the user mentions "OpenTelemetry", "OTLP", "traces", "spans", "Activity", "ActivitySource", "metrics", "IMeterFactory", "Meter", "Counter", "Histogram", "Gauge", "telemetry", "observability", "distributed tracing", "OTEL", or "Aspire Dashboard".

    Also in 3 projects that use this

  • MovGP0Skill

    modern-csharp

    Modern C# style guidance for Bendex and MicroSea code changes, including primary constructors, expression-bodied members, var usage, target-typed new, lambdas, and pattern matching.

    Also in 3 projects that use this

  • MicrosoftSkill

    resilience

    Apply resilience patterns (retry, backoff, circuit breaking) when writing or reviewing code that makes outbound HTTP/REST calls, database operations, or any I/O that can experience transient failures. Use this skill when: (1) writing new code that calls external services or APIs, (2) reviewing code that uses fetch, HTTP clients, or service-to-service calls, (3) adding queue consumers or workers that interact with remote systems, (4) debugging intermittent failures in production.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 64 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All error utilities live in pydita.loggingutils.

    line 11

“Common” is measured: kept by at least 6 in 10 of the 64 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Overview

pydita uses a shared mutable dict as its error accumulator, passed by reference through every API call. Errors are never raised and swallowed silently — they are recorded as ErrorRecord objects keyed by a string identifier (usually an absolute file path or a key name).

All error utilities live in pydita.loggingutils.


Core types

SEVERITY enum

Ordered severity levels (ascending):

from pydita.loggingutils import SEVERITY

SEVERITY.OTHER   # 0 — unclassified
SEVERITY.DEBUG   # 1 — debug trace
SEVERITY.INFO    # 2 — informational
SEVERITY.ERROR   # 3 — recoverable error
SEVERITY.WARN    # 4 — warning (higher than ERROR in pydita's ordering)
SEVERITY.FATAL   # 5 — unrecoverable

Note: In pydita's OrderedEnum, WARN (4) is higher than ERROR (3). This is intentional — WARNings are considered more severe than recoverable ERRORs.

ErrorRecord

from pydita.loggingutils import ErrorRecord, SEVERITY

rec = ErrorRecord(
    err=exception,          # Exception — required
    operation="myFunc()",   # str — which function caught it
    severity=SEVERITY.ERROR,
    key="file://abs/path",  # str — the dict key this belongs to
    traceBack="...",        # str — traceback.format_exc() output
)

str(rec)  # '[ERROR] "file://path" myFunc(): <exception message>'

Recording errors

Direct function call

from pydita import loggingutils
import traceback

errors = {}

try:
    do_something()
except Exception as e:
    loggingutils.recordError(
        errors,
        key="my-operation",
        err=e,
        operation="do_something()",
        severity=loggingutils.SEVERITY.ERROR,
        traceBack=traceback.format_exc(),
    )

Via DitaContext

ctx.recordError(
    key="some-key",
    error=exception,
    operation="myProcessor()",
    severity=SEVERITY.WARN,
)
# Delegates to loggingutils.recordError(ctx.getErrors(), ...)

Errors dict structure

errors = {
    "/abs/path/to/file.ditamap": [ErrorRecord, ErrorRecord, ...],
    "key-name":                  [ErrorRecord],
}
  • One key can have multiple ErrorRecord objects (e.g., multiple parse errors in the same file).
  • The key is any string — typically a file URI, file path, or DITA key name.

Reporting errors

Full report string

from pydita import loggingutils

report = loggingutils.reportErrors(errors, showTraceBack=False)
print(report)
# Have 3 total errors:
# [ERROR] "path/to/sub.ditamap" resolveSubmap(): ...
# [WARN]  "key-name" constructKeySpace(): ...

Filter by severity

from pydita.loggingutils import SEVERITY

fatal_errors = {
    k: [r for r in recs if r.getSeverity() >= SEVERITY.FATAL]
    for k, recs in errors.items()
    if any(r.getSeverity() >= SEVERITY.FATAL for r in recs)
}

Check for any errors above a threshold

def has_errors(errors: dict, min_severity=SEVERITY.ERROR) -> bool:
    return any(
        r.getSeverity() >= min_severity
        for recs in errors.values()
        for r in recs
    )

Logging helpers

pydita provides Logger (abstract) and ConsoleLogger (concrete) for structured log output:

from pydita.loggingutils import ConsoleLogger, SEVERITY

log = ConsoleLogger(logging_level=SEVERITY.WARN)
log.debug("ignored — below WARN threshold")
log.warn("printed: [WARN] printed: ...")
log.error("printed: [ERROR] ...")
log.fatal("printed: [FATAL] ...")

# Print raw message without severity prefix
log.print("Raw message output")

Implement a custom logger by subclassing Logger and overriding _log_message():

from pydita.loggingutils import Logger, SEVERITY

class FileLogger(Logger):
    def __init__(self, path: str):
        super().__init__(logging_level=SEVERITY.INFO)
        self._file = open(path, "w")

    def _log_message(self, message, severity: SEVERITY):
        if severity >= self.get_logging_level():
            self._file.write(f"[{severity.name}] {message}\n")

Best practices

RuleRationale
Create one errors = {} per pipeline runPrevents cross-contamination between independent runs
Pass errors to every pydita functionMissing it silently discards errors
Check errors after resolveMap() and after KeyspaceManager()Both can fail silently
Use traceBack=traceback.format_exc() in except blocksMakes root-cause analysis much easier
Filter by SEVERITY.ERROR or higher for pass/fail decisionsDEBUG and INFO records should not count as failures

See also

  • context-setup — how errors is shared across the full pipeline
  • map-resolve — error patterns during map resolution

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.