[PR #12270] fix: handle custom tool import failures gracefully in registry #14143

Open
opened 2026-02-16 18:18:57 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12270

State: open
Merged: No


Summary

Fixes #12269 — the tool registry now catches and logs errors when a custom tool fails to import (e.g. due to unresolvable dependencies) instead of crashing the entire registry initialization.

Changes

  • packages/opencode/src/tool/registry.ts — wrap import(match) in try/catch, log warning and skip tools that fail to load
  • packages/opencode/test/tool/registry.test.ts — fix the loads tools with external dependencies without crashing test to verify resilience (registry doesn't crash) rather than expecting the tool to be loaded when its dependencies can't be resolved

Context

Commit 556adad67 (#12227) added a test that creates a custom tool importing cowsay, but the dependency is never installed in the test's temp directory. This causes a deterministic failure on CI that blocks all PRs targeting dev:

error: Cannot find package 'cowsay' from '/tmp/opencode-test-xxx/.opencode/tools/cowsay.ts'
(fail) tool.registry > loads tools with external dependencies without crashing [269.71ms]

881 pass / 1 fail

The production code fix (try/catch) is also good defensive programming — if bun install fails for any reason (network error, disk full, etc.), the registry should still work for all other tools rather than crashing entirely.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12270 **State:** open **Merged:** No --- ## Summary Fixes #12269 — the tool registry now catches and logs errors when a custom tool fails to import (e.g. due to unresolvable dependencies) instead of crashing the entire registry initialization. ## Changes - **`packages/opencode/src/tool/registry.ts`** — wrap `import(match)` in try/catch, log warning and skip tools that fail to load - **`packages/opencode/test/tool/registry.test.ts`** — fix the `loads tools with external dependencies without crashing` test to verify resilience (registry doesn't crash) rather than expecting the tool to be loaded when its dependencies can't be resolved ## Context Commit `556adad67` (#12227) added a test that creates a custom tool importing `cowsay`, but the dependency is never installed in the test's temp directory. This causes a deterministic failure on CI that blocks **all PRs** targeting `dev`: ``` error: Cannot find package 'cowsay' from '/tmp/opencode-test-xxx/.opencode/tools/cowsay.ts' (fail) tool.registry > loads tools with external dependencies without crashing [269.71ms] 881 pass / 1 fail ``` The production code fix (try/catch) is also good defensive programming — if `bun install` fails for any reason (network error, disk full, etc.), the registry should still work for all other tools rather than crashing entirely.
yindo added the pull-request label 2026-02-16 18:18:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14143