Skip to content

fix(timeout): accept Go duration strings and report timeouts clearly (#12)#16

Merged
kavix merged 1 commit into
kavix:mainfrom
AzarAI-TOP:fix/timeout-duration-parsing
Jun 13, 2026
Merged

fix(timeout): accept Go duration strings and report timeouts clearly (#12)#16
kavix merged 1 commit into
kavix:mainfrom
AzarAI-TOP:fix/timeout-duration-parsing

Conversation

@AzarAI-TOP

Copy link
Copy Markdown
Contributor

Description

Fixes #12.

The --timeout / -t flag parsed its value with time.ParseDuration(value + "s"), unconditionally appending s. That only worked for bare-second numbers and mishandled the duration strings the issue explicitly asks to support:

Input Old behaviour New behaviour
--timeout 30 30s 30s ✓ (unchanged)
--timeout 1m 1ms1 millisecond, silently wrong 1m
--timeout 5s error (5ss) 5s
--timeout 500ms error (500mss) 500ms
--timeout notaduration confusing parse error invalid timeout "notaduration": want a number of seconds or a duration like 5s, 1m, 500ms

Changes

  • parseTimeout helper (main.go): a bare number is treated as seconds (keeps the documented --timeout <seconds> default), anything else is parsed as a Go duration string (5s, 1m, 500ms, 1m30s). Negative / unparseable values now error clearly.
  • Clear timeout message (client/client.go): when a request actually times out, surface request timed out after 30s (increase or disable with --timeout) instead of the raw context deadline exceeded transport error.
  • Updated the --timeout help text.
  • No change to the default (30s) or to the saved-request (run) path.

Maps to the issue's acceptance criteria:

  • --timeout flag accepts duration strings
  • Applied to the HTTP client
  • Clear error message on timeout (not a generic Go error)
  • Default remains a reasonable 30s
  • Test coverage added

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update (help text updated in-tree)

How Has This Been Tested?

  • Added unit tests — CLI parser (main_test.go, incl. a regression test that 1m == 1 minute, not 1ms) and client timeout behaviour (client/timeout_test.go, a firing timeout + a request that completes in time).
  • Tested via go test ./... locally — all packages pass.
  • Compiled and tested via local binary:
    • kurl --timeout 500ms … → works
    • kurl --timeout 1ms https://example.comrequest timed out after 1ms (increase or disable with --timeout)
    • kurl --timeout notaduration … → clear validation error

Checklist

  • My code follows the style guidelines of this project (gofmt, go vet clean)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (help text)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes

The --timeout/-t flag parsed its value as `time.ParseDuration(value + "s")`,
unconditionally appending "s". That only worked for bare-second numbers and
mishandled the duration strings the flag is meant to take:

  --timeout 1m     -> ParseDuration("1ms") = 1 millisecond (silently wrong!)
  --timeout 500ms  -> error ("500mss")
  --timeout 5s     -> error ("5ss")

Add a parseTimeout helper that accepts both forms: a bare number is treated
as seconds (keeping the documented `--timeout <seconds>` default), and any
other value is parsed as a Go duration string (5s, 1m, 500ms, 1m30s).
Negative and unparseable values now produce a clear error.

Also surface a readable message when a request actually times out, instead
of the raw `context deadline exceeded` transport error:

  request timed out after 30s (increase or disable with --timeout)

Adds CLI-parser tests (incl. a regression test that "1m" == 1 minute) and
client tests covering a firing timeout and a request that completes in time.
Updates the --timeout help text. No change to the default (30s) or to the
saved-request path.

Closes #12

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kavix kavix merged commit c5b7af2 into kavix:main Jun 13, 2026
1 check passed
@AzarAI-TOP AzarAI-TOP deleted the fix/timeout-duration-parsing branch June 15, 2026 05:33
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.

Add --timeout flag for request timeout control

2 participants