Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

fix(envd): malformed error message %!w(<nil>) when watch path is not a directory

Open Beginner friendly
#3,581 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
go

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.

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

  1. Start envd.
  2. Create a normal file /home/user/test.txt.
  3. Call CreateWatcher on /home/user/test.txt.
  4. Observed Error: connect.CodeInvalidArgument with message "path /home/user/test.txt not a directory: %!w(<nil>)".
  5. Expected Error: connect.CodeInvalidArgument with 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
Dominant language
Go
Stars
1.6k
Forks
448
PR merge metrics
No merged PRs in 30d

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from e2b-dev/runtime

All issues in e2b-dev/runtime

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.