Skip to main content
Building a tool instance can fail two ways — the tool isn’t registered, or it is but its factory threw. Two error classes keep them apart.

Quick Start

1

Catch and Discriminate


Why Two Classes

Before PR #4902, building a missing tool and building a broken tool both returned null — hiding real bugs. Now the two failures are distinct. ToolsRegistry.create throws these instead of a generic Error, so callers can react to each.

Error Fields


Return null Instead of Throwing

When a tool is optional, tryCreateToolInstance returns null for a missing id — but still throws ToolConstructionError if the registered factory fails, so a broken tool never looks like a missing one.

Validation Errors

ToolValidationError is separate — it comes from validating a tool object, not building a factory instance.
validate_tool delegates to the tool’s own validate() when present, listing every problem it finds.

Best Practices

Catch ToolNotRegisteredError and ToolConstructionError separately — one is a config/name fix, the other a bug in the factory.
ToolConstructionError.cause carries the underlying error the factory threw — log it, don’t swallow it.
Prefer returning null over catching for tools that may legitimately be absent, while still letting build failures surface.

Factory Registry

Register builders, construct instances

Custom Tools

Name-keyed registry & validation