Skip to content

fix: handle conn.Write and fmt.Fprintf errors in echo/webserver examples (PILOT-299)#6

Open
matthew-pilot wants to merge 1 commit into
mainfrom
openclaw/pilot-299-20260530-164000
Open

fix: handle conn.Write and fmt.Fprintf errors in echo/webserver examples (PILOT-299)#6
matthew-pilot wants to merge 1 commit into
mainfrom
openclaw/pilot-299-20260530-164000

Conversation

@matthew-pilot
Copy link
Copy Markdown
Collaborator

Summary

  • Ticket: PILOT-299
  • Scope: 2 files, +15/−5 LoC
  • Tier: small

What

go/echo/main.go and go/webserver/main.go silently discarded write errors (conn.Write, fmt.Fprintf). Since these are example programs that users copy, they should model correct error handling.

Changes

  • echo: Log and return on conn.Write error for both raw and prefixed echo paths
  • webserver: Log fmt.Fprintf errors in / and /status handlers (HTTP handler teardown is framework-managed)

Verification

  • go build ./... ✓ (both echo and webserver)
  • go vet ./...
  • go test ./...

Checklist

  • Build passes
  • Tests pass
  • No denied paths touched

…xamples (PILOT-299)

Previously, conn.Write errors in go/echo/main.go and fmt.Fprintf errors
in go/webserver/main.go were silently discarded. Since these are example
programs that users copy, they should model correct error handling.
Added log.Printf on write errors with a return (echo) or no-op continue
(webserver HTTP handler where the framework handles teardown).
@matthew-pilot
Copy link
Copy Markdown
Collaborator Author

📊 PR Status — #6 PILOT-299

Field Value
State OPEN
Mergeable ✅ MERGEABLE
Draft No
Branch openclaw/pilot-299-20260530-164000main
Files 2 files, +15/−5 (go/echo/main.go, go/webserver/main.go)
Labels (none)

CI Checks (4/4 passing)

Check Result
go-examples ✅ pass
python-examples ✅ pass
shell-examples ✅ pass
security/snyk ✅ pass

Canary

Not applicable — examples repo, no canary configured.

@matthew-pilot
Copy link
Copy Markdown
Collaborator Author

🔍 PR Explanation — #6 PILOT-299

What this does

Fixes silent error discarding in two Go example programs that users commonly copy as starter code.

The problem

go/echo/main.go and go/webserver/main.go called conn.Write and fmt.Fprintf without checking the returned error. In example code that users copy-paste, this teaches a bad pattern — write errors (closed connections, I/O faults) are silently ignored.

The fix

go/echo/main.go (+8/−2):

  • After conn.Write(buf[:n]) in both the raw-echo and prefixed-echo paths, logs and returns on error
  • Switched from if err := ... short-declaration to explicit err assignment for clarity

go/webserver/main.go (+7/−3):

  • Logs fmt.Fprintf errors in the / and /status handlers
  • HTTP handler cleanup is framework-managed, so no explicit response teardown needed

Impact

  • Backwards compatible — behavior unchanged on success, only adds visible error surfacing
  • Security-neutral — write errors are not attacker-controlled
  • Docs/examples only — no production code paths touched

CI

4/4 green (go-examples ✅, python-examples ✅, shell-examples ✅, snyk ✅)

@matthew-pilot
Copy link
Copy Markdown
Collaborator Author

🔍 Matthew Explains — #6 PILOT-299

What this does

Adds error handling for conn.Write and fmt.Fprintf calls in the echo and webserver Go examples that previously silently discarded write errors.

Why

These are example programs that users copy as templates. Silently ignoring write errors models bad practice. Real programs should at minimum log the error so operators can detect broken connections or resource exhaustion.

Changes (2 files, +15/−5 LoC)

  • go/echo/main.go — log and return on conn.Write error for both raw and prefixed echo paths (+8/−3)
  • go/webserver/main.go — log fmt.Fprintf errors in / and /status HTTP handlers (+7/−2)

For the webserver, HTTP handler teardown is framework-managed, so the handler only logs the error rather than returning early.

Canary

Not configured for examples repo.

@matthew-pilot
Copy link
Copy Markdown
Collaborator Author

📊 Matthew PR Status — #6 PILOT-299

Field Value
State OPEN · MERGEABLE ✅
Draft No
Branch openclaw/pilot-299-20260530-164000main
Files 2 files, +15/−5 (go/echo/main.go, go/webserver/main.go)
Labels (none)

CI Checks (3/3 passing)

Check Result
go-examples ✅ pass
python-examples ✅ pass
shell-examples ✅ pass

Verdict

CLEAN — all CI green, small fix (2 files, +15/−5). Safe to merge.

@matthew-pilot
Copy link
Copy Markdown
Collaborator Author

📊 Status — PILOT-299

  • PR state: Open · Mergeable · No conflicts · No reviews yet
  • Canary: Not run — no canary job found for this PR
  • Jira: QA/IN-REVIEW — "examples/go: echo + webserver ignore conn.Write errors" · Unassigned · Last updated 2026-05-30
  • Operator activity: None — no comments/reviews from @TeoSlayer on this PR yet

🤖 auto-status by matthew-pilot

@matthew-pilot
Copy link
Copy Markdown
Collaborator Author

🔍 PR Clarification — PILOT-299

@TeoSlayer — this PR is ready for review:

  • What: Fixes silent error discarding in conn.Write / fmt.Fprintf calls in the echo and webserver Go examples
  • Scope: 2 files, +15/−5 LoC (tier: small)
  • CI: All 4 checks green (go-examples, python-examples, shell-examples, security/snyk)
  • Mergeable: ✅ No conflicts
  • Canary: N/A (examples repo, no deployables)

No operator comments or reviews since opening. Let me know if you have questions or if this looks good to merge.

🤖 auto-clarify by matthew-pilot

@matthew-pilot
Copy link
Copy Markdown
Collaborator Author

🤖 PR Clarification — Review Requested

#6: fix: handle conn.Write and fmt.Fprintf errors in echo/webserver examples (PILOT-299)
Status: open | Mergeable: yes (clean) ✅

Summary

Summary

  • Ticket: PILOT-299
  • Scope: 2 files, +15/−5 LoC
  • Tier: small

What

go/echo/main.go and go/webserver/main.go silently discarded write errors (conn.Write, fmt.Fprintf). Since these are example programs that users copy, they should model correct error handling.

Changes

  • echo: Log and return on conn.Write error for both raw and prefixed echo paths
  • webserver: Log fmt.Fprintf errors in / and /status handlers (HTTP handler teardown is framework-managed)

Verification

  • go build ./......

Changes

+15/−5 across 2 file(s):

  • go/echo/main.go (+8/−2) [modified]
  • go/webserver/main.go (+7/−3) [modified]

CI Status

python-examples ✅ | go-examples ✅ | shell-examples ✅

Labels

(none)


👋 @TeoSlayer — this PR is ready for your review.

matthew-pr-worker • 2026-06-01T12:55:00Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant