can1357/oh-my-pi · error · ArgumentError
tool.#{name}(...) expects a Hash of arguments (got #{positio
Error message
tool.#{name}(...) expects a Hash of arguments (got #{positional.class}) What it means
The `tool.<name>(...)` bridge wrapper accepts its arguments either as a single positional Hash or as Ruby keyword arguments, which are then merged and forwarded as the tool's JSON argument object. If a non-Hash positional argument is passed (String, Array, nil-adjacent scalars other than nil), the wrapper raises ArgumentError because tool arguments must serialize to a JSON object.
Source
Thrown at packages/coding-agent/src/eval/rb/prelude.rb:334
raise((data.is_a?(Hash) ? data["error"] : nil) || "bridge call #{name.inspect} failed")
end
data["value"]
end
def stringify_keys(hash)
out = {}
hash.each { |k, v| out[k.to_s] = v }
out
end
def tool_call(name, positional, kwargs)
merged =
if positional.nil?
{}
elsif positional.is_a?(Hash)
stringify_keys(positional)
else
raise ArgumentError, "tool.#{name}(...) expects a Hash of arguments (got #{positional.class})"
end
merged.merge!(stringify_keys(kwargs)) if kwargs && !kwargs.empty?
merged[INTENT_FIELD] = "rb prelude" unless merged.key?(INTENT_FIELD)
call(name, merged)
end
end
# `tool[:name]` form — a reusable one-tool callable.
class OmpToolCallable
def initialize(name)
@name = name
end
def call(args = nil, **kwargs)
OmpBridge.tool_call(@name, args, kwargs)
end
def to_procView on GitHub (pinned to 9690622007)
Solutions
- Wrap the arguments in a Hash: `tool.read_file(path: 'x.txt')` or `tool.read_file('path' => 'x.txt')`.
- If you have a JSON string, `JSON.parse(it)` it into a Hash first.
- Check the tool's expected schema (via the host tool list) and supply every argument as hash keys.
Example fix
// before
tool.read_file('/etc/hosts') # ArgumentError: got String
// after
tool.read_file(path: '/etc/hosts') # or { 'path' => '/etc/hosts' } Defensive patterns
Strategy: type-guard
Validate before calling
raise ArgumentError, 'args must be a Hash' unless args.nil? || args.is_a?(Hash)
Type guard
def hash_args?(args) args.nil? || args.is_a?(Hash) end
Try / catch
begin
tool.read_file(raw_arg)
rescue ArgumentError => e
raise unless e.message =~ /expects a Hash/
tool.read_file('path' => raw_arg)
end Prevention
- Always build tool arguments as Hashes (or keyword args) — never pass positional scalars.
- JSON.parse any JSON strings into Hashes before passing to tool.<name>.
- Check the tool schema for required parameter names before invoking.
When it happens
Trigger: Calling `tool.read_file('path/to/file')` with a bare string, `tool.search(['a','b'])` with an array, or passing a non-nil scalar as the only positional argument instead of `{ 'path' => ... }` or keyword form.
Common situations: Assuming positional strings map to a conventional first parameter name; converting Python-style `tool(name, args)` calls to Ruby incorrectly; passing a JSON string directly instead of a parsed Hash.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- query cannot be combined with offset/limit
- At least one output ID is required
- tool bridge is unavailable in this kernel
- bridge call #{name.inspect}: non-JSON response: #{resp.body.
- {} and {} are the same file
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/9ebee1f522142c4b.
Report an issue: GitHub.