fix(envd): malformed error message %!w(<nil>) when watch path is not a directory
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.6k
- Forks
- 438
- PR merge metrics
- No merged PRs in 30d
Description
Problem
In packages/envd/internal/services/filesystem/watch.go and watch_sync.go, the guest agent's filesystem service checks whether a path targeted for watching is a valid directory:
info, err := os.Stat(watchPath)
if err != nil {
if os.IsNotExist(err) {
return connect.NewError(connect.CodeNotFound, fmt.Errorf("path %s not found: %w", watchPath, err))
}
return connect.NewError(connect.CodeInternal, fmt.Errorf("error statting path %s: %w", watchPath, err))
}
if !info.IsDir() {
return connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("path %s not a directory: %w", watchPath, err))
}
When os.Stat(watchPath) succeeds for a non-directory (e.g. a regular file, FIFO, or socket), err is nil. Because err is nil, Go's fmt.Errorf %w verb produces the malformed string %!w(<nil>).
Clients and Connect-RPC error logs receive corrupted messages such as:
path /home/user/file.txt not a directory: %!w(<nil>)
Root Cause
fmt.Errorf was invoked with the error-wrapping format verb %w against a nil error reference instead of formatting a clean static error message:
| Location | Current Formatting | Output for regular file /tmp/test.txt |
Expected Formatting |
|---|---|---|---|
watch.go:L44 |
fmt.Errorf("path %s not a directory: %w", watchPath, err) |
"path /tmp/test.txt not a directory: %!w(<nil>)" |
"path /tmp/test.txt is not a directory" |
watch_sync.go:L171 |
fmt.Errorf("path %s not a directory: %w", watchPath, err) |
"path /tmp/test.txt not a directory: %!w(<nil>)" |
"path /tmp/test.txt is not a directory" |
This formatting also aligns with other filesystem endpoints in packages/envd/internal/services/filesystem/dir.go:L131 ("path is not a directory: %s").
Reproduction Steps
- Start
envd. - Create a normal file
/home/user/test.txt. - Call
CreateWatcheron/home/user/test.txt. - Observed Error:
connect.CodeInvalidArgumentwith message"path /home/user/test.txt not a directory: %!w(<nil>)". - Expected Error:
connect.CodeInvalidArgumentwith message"path /home/user/test.txt is not a directory".
Technical Context
- Files affected:
packages/envd/internal/services/filesystem/watch.go,packages/envd/internal/services/filesystem/watch_sync.go - Subsystem: Guest Agent (
envd) / Filesystem Service - Impact: Low (Error cleanliness, log readability, and API response quality)
Proposed Changes
| # | Change | File(s) Affected | Complexity |
|---|---|---|---|
| 1 | Replace fmt.Errorf("path %s not a directory: %w", watchPath, err) with fmt.Errorf("path %s is not a directory", watchPath) |
watch.go, watch_sync.go |
Trivial |
| 2 | Add unit test TestCreateWatcher_NotADirectory asserting clean message without %!w |
watch_test.go |
Low |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/envd/internal/services/filesystem/watch.go and watch_sync.go, focusing on the non-directory checks described in the issue. Add or update the TestCreateWatcher_NotADirectory test in watch_test.go, then run the filesystem service tests. Done means both watcher paths return a clean invalid-argument message without %!w when given a non-directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100