aws / aws/amazon-q-developer-cli

Error when `q chat` attempts to read an empty file using `fs_read`

Open
#1,664 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
439
PR merge metrics
No merged PRs in 30d

Description

### Checks

- [x] I have searched [github.com/aws/amazon-q-developer-cli/issues](https://github.com/aws/amazon-q-developer-cli/issues?q=) and there are no duplicates of my issue
- [x] I have run `q doctor` in the affected terminal session
- [x] I have run `q restart` and replicated the issue again

### Operating system

macOS 15.4.1 (24E263)

### Expected behaviour

`fs_read` has doesn't seem to handle empty files very well.

Probably need to check if `line_count` is empty and then either give a more sensible error message or even better signal to the agent that the file is indeed empty. Unfortunately there doesn't seem to be a OutputKind of Empty. I wonder what the agent would do if you just returned a empty string?

### Actual behaviour

```
Execution failed after 0.0s:
starting index: 1 is outside of the allowed range: (0, 0)
```

The error is generated in https://github.com/aws/amazon-q-developer-cli/blob/main/crates/q_chat/src/tools/fs_read.rs#L145

### Steps to reproduce

```
mkdir -p ~/tmp/test
cd ~/tmp/test/
touch __python_file_.py
q chat
```

Give q the prompt

```
summarize the file called '__python_file_.py'
```

Results

```
I'll help you summarize the file __python_file_.py. First, let me check if this file exists in your current directory.

🛠️ Using tool: fs_read (trusted)

● Reading file: __python_file_.py, from line 1 to 1

● Execution failed after 0.0s:
starting index: 1 is outside of the allowed range: (0, 0)

It seems the file __python_file_.py doesn't exist in your current directory. Let me check if it exists elsewhere by listing the files in your current directory.

🛠️ Using tool: fs_read (trusted)

● Reading directory: . with maximum depth of 0

● Completed in 0.0s

I see the file __python_file_.py exists in your current directory, but it appears to be empty (0 bytes). The file was created today at 00:13, but it doesn't contain any code or content to summarize.

Would you like me to:
1. Create some Python code in this file?
2. Check if you meant a different Python file?
3. Help you with something else related to this file?
```

### Environment

```yaml

[q-details]
version = "1.9.1"
hash = "5d2c2807cab9bc6c9dc5fcd05f92c7a979e8a4f7"
date = "2025-04-29T06:22:42.917989Z (6d ago)"
variant = "full"

[system-info]
os = "macOS 15.4.1 (24E263)"
chip = "Apple M3 Pro"
total-cores = 12
memory = "36.00 GB"

[environment]
cwd = "/Users/USER/tmp/test"
cli-path = "/Users/USER/tmp/test"
os = "Mac"
shell-path = "/bin/zsh"
shell-version = "5.9"
terminal = "iTerm 2"
install-method = "brew"

[env-vars]
PATH = "/Users/USER/.toolbox/bin:/usr/local/sbin:/Users/USER/.cargo/bin:/Users/USER/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/Wireshark.app/Contents/MacOS:/Users/USER/.local/bin:/Users/USER/.cargo/bin:/Applications/iTerm.app/Contents/Resources/utilities:/Users/USER/Library/Application Support/JetBrains/Toolbox/scripts:/apollo/env/SDETools/bin:/Users/USER/bin:/Users/USER/workspace/Git-review-tools/src/Git-review-tools/bin:/Users/USER/workspace/LazyCR/target/release"
QTERM_SESSION_ID = "b2934faa68f04faaa79b3441fe05c3df"
Q_SET_PARENT_CHECK = "1"
Q_TERM = "1.9.1"
SHELL = "/bin/zsh"
TERM = "xterm-256color"
__CFBundleIdentifier = "com.googlecode.iterm2"

[chat-settings]
interactive=true

[chat-trusted_tools]

[chat-failed_request_ids]
none

[chat-context]
current_profile=default
profiles=
default

global_context=
.amazonq/rules/**/*.md
README.md
AmazonQ.md

profile_context=none

files=none
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.