Skip to content

fix: translate raw Go timeout errors to human-readable messages#26

Merged
rafia9005 merged 2 commits into
mainfrom
dev
Jun 17, 2026
Merged

fix: translate raw Go timeout errors to human-readable messages#26
rafia9005 merged 2 commits into
mainfrom
dev

Conversation

@rafia9005

@rafia9005 rafia9005 commented Jun 17, 2026

Copy link
Copy Markdown
Member

Changes

scheduler.go — added friendlyHTTPError() and friendlyPingError() that translate raw Go/networking errors (ECONNREFUSED, ECONNRESET, ENETUNREACH, ETIMEDOUT, timeout) into clear failure messages instead of passing cryptic Go-internal strings like context deadline exceeded (Client.Timeout exceeded while awaiting headers) to incident logs.

monitor_request.go — bumped minimum timeout from 1s to 5s. A 1s timeout was near-guaranteed to fail for real endpoints.

monitor_handler.go — replaced context.Background() on initial create/update checks with context.WithTimeout so the check goroutine has a bounded lifetime.

Before

Error: Get "https://test.terarush.dev/": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

After

Request timed out after 10 seconds — the server may be down or blocking connections

Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com

Summary by CodeRabbit

  • New Features

    • Added --init CLI flag to generate and install systemd service file
    • Improved error messages for network failures with clearer descriptions
  • Improvements

    • Timeout field now required for monitor creation with minimum 5-second value
    • Enhanced monitor check execution with proper timeout context management

rafia9005 and others added 2 commits June 15, 2026 10:53
- friendlyHTTPError/friendlyPingError: decode syscall.Errno and net.Error
  into readable failure messages instead of raw Go error strings
- Bump min timeout validation from 1s to 5s in create/update requests
- Replace context.Background() on initial checks with bounded context
  using monitor timeout + 10s buffer

Fixes issue where users saw cryptic 'context deadline exceeded
(Client.Timeout exceeded while awaiting headers)' in incident logs

Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
@rafia9005 rafia9005 merged commit 86710db into main Jun 17, 2026
2 of 3 checks passed
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 56162f1a-fd91-474b-99e6-4592d6c8dacd

📥 Commits

Reviewing files that changed from the base of the PR and between ada0cb4 and 0011468.

📒 Files selected for processing (5)
  • internal/pkg/config/config.go
  • main.go
  • modules/monitors/domain/service/scheduler.go
  • modules/monitors/dto/request/monitor_request.go
  • modules/monitors/handler/monitor_handler.go

📝 Walkthrough

Walkthrough

Adds a --init CLI flag that generates and writes a systemd unit file for ping-uptime then exits. Separately, enforces a minimum timeout of 5 seconds on monitor create/update requests, runs post-create/update PerformCheck calls under a bounded context.WithTimeout, and replaces raw network error strings in the scheduler with human-readable messages.

Changes

Systemd Service File Generation

Layer / File(s) Summary
--init flag registration and systemd unit generation
internal/pkg/config/config.go, main.go
config.go registers the --init boolean flag (default false). main.go imports fmt and adds an INIT branch that resolves the executable path, formats the systemd unit file content, writes it to /etc/systemd/system/ping-uptime.service, prints systemctl enable/start instructions, and calls os.Exit(0).

Monitor Timeout Enforcement and Friendly Error Messages

Layer / File(s) Summary
Timeout field in DTO and timeout-bounded handler checks
modules/monitors/dto/request/monitor_request.go, modules/monitors/handler/monitor_handler.go
CreateMonitorRequest gains a required Timeout field with min=5 validation. UpdateMonitorRequest.Timeout minimum raised from 1 to 5. In both CreateMonitor and UpdateMonitor, the immediate PerformCheck(context.Background()) call is replaced with a goroutine running PerformCheck under context.WithTimeout(monitor.Timeout + 10s) with deferred cancel.
Friendly error helpers in scheduler
modules/monitors/domain/service/scheduler.go
Imports extended with errors, os, and syscall. performHTTPCheck and performPingCheck now call new friendlyHTTPError and friendlyPingError helpers instead of returning raw err.Error(). Both helpers unwrap *url.Error/*net.OpError, check os.ErrDeadlineExceeded, map specific syscall.Errno values to readable messages, and truncate unknown error text.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hippity-hop, a flag appears,
--init writes service files, no fears!
Timeouts now bound each network call,
Friendly errors cushion the fall.
Raw errnos turned to words so clear —
The rabbit's code brings joy and cheer! 🎉

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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