-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patherrors.rb
More file actions
56 lines (44 loc) · 1.52 KB
/
errors.rb
File metadata and controls
56 lines (44 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
module ClaudeAgentSDK
# Base exception for all Claude SDK errors
class ClaudeSDKError < StandardError; end
# Raised when unable to connect to Claude Code
class CLIConnectionError < ClaudeSDKError; end
# Raised when the control protocol does not respond in time
class ControlRequestTimeoutError < CLIConnectionError; end
# Raised when Claude Code is not found or not installed
class CLINotFoundError < CLIConnectionError
def initialize(message = 'Claude Code not found', cli_path: nil)
message = "#{message}: #{cli_path}" if cli_path
super(message)
end
end
# Raised when the CLI process fails
class ProcessError < ClaudeSDKError
attr_reader :exit_code, :stderr
def initialize(message, exit_code: nil, stderr: nil)
@exit_code = exit_code
@stderr = stderr
message = "#{message} (exit code: #{exit_code})" if exit_code
message = "#{message}\nError output: #{stderr}" if stderr
super(message)
end
end
# Raised when unable to decode JSON from CLI output
class CLIJSONDecodeError < ClaudeSDKError
attr_reader :line, :original_error
def initialize(line, original_error)
@line = line
@original_error = original_error
super("Failed to decode JSON: #{line[0...100]}...")
end
end
# Raised when unable to parse a message from CLI output
class MessageParseError < ClaudeSDKError
attr_reader :data
def initialize(message, data: nil)
@data = data
super(message)
end
end
end