Quick Start
1
Catch and Discriminate
Why Two Classes
Before PR #4902, building a missing tool and building a broken tool both returnednull — 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
Handle both classes at build sites
Handle both classes at build sites
Catch
ToolNotRegisteredError and ToolConstructionError separately — one is a config/name fix, the other a bug in the factory.Log err.cause on construction failure
Log err.cause on construction failure
ToolConstructionError.cause carries the underlying error the factory threw — log it, don’t swallow it.Use tryCreateToolInstance for optional tools
Use tryCreateToolInstance for optional tools
Prefer returning
null over catching for tools that may legitimately be absent, while still letting build failures surface.Related
Factory Registry
Register builders, construct instances
Custom Tools
Name-keyed registry & validation

