Skip to content

Comments

fix(scheduler): guard nil errors; drain request body; docs/tests#20

Merged
hyp3rd merged 3 commits intomainfrom
feat/scheduler
Jan 21, 2026
Merged

fix(scheduler): guard nil errors; drain request body; docs/tests#20
hyp3rd merged 3 commits intomainfrom
feat/scheduler

Conversation

@hyp3rd
Copy link
Owner

@hyp3rd hyp3rd commented Jan 21, 2026

  • Add isNilError and avoid logging nil errors in logError (import reflect).
  • Improve readBody to fully drain and tighten error handling.
  • Align tests with defaultMaxRetries/defaultRetryCount; update expectations for attempts, intervals, and payload fields.
  • Add tests: validation for unsupported method/invalid job, max-runs stop, and enforcing MaxBodyBytes for callback payloads.
  • Update README with scheduler options, retry policy, schedule fields, and callback payload schema (job_id, scheduled_at, started_at, finished_at, attempts, success, status_code, error, response_body).

- Add isNilError and avoid logging nil errors in logError (import reflect).
- Improve readBody to fully drain and tighten error handling.
- Align tests with defaultMaxRetries/defaultRetryCount; update expectations for
  attempts, intervals, and payload fields.
- Add tests: validation for unsupported method/invalid job, max-runs stop,
  and enforcing MaxBodyBytes for callback payloads.
- Update README with scheduler options, retry policy, schedule fields, and
  callback payload schema (job_id, scheduled_at, started_at, finished_at,
  attempts, success, status_code, error, response_body).
Copilot AI review requested due to automatic review settings January 21, 2026 17:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves error handling in the scheduler package by adding nil error guards, fixing a bug in the readBody function, and enhancing test coverage. The changes include adding comprehensive validation tests, aligning test expectations with defined constants, and updating documentation with detailed scheduler configuration options.

Changes:

  • Fixed readBody to properly handle successful body draining without returning spurious errors
  • Added isNilError helper to prevent logging typed nil errors
  • Added validation tests for unsupported methods, invalid jobs, MaxRuns behavior, and callback payload body limits
  • Replaced hardcoded test values with constants for better maintainability
  • Enhanced README with scheduler options, retry policy details, and callback payload schema

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/scheduler/scheduler.go Added isNilError guard function using reflection, fixed readBody bug that incorrectly wrapped nil errors
tests/scheduler_test.go Added validation tests for error cases, MaxRuns stopping behavior, and callback body size limits
tests/retrier_test.go Replaced hardcoded retry values with defaultMaxRetries and defaultRetryCount constants
README.md Added comprehensive documentation for scheduler options, schedule fields, retry policy, and callback payload structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add WithURLValidator option and urlValidator field to Scheduler
- Default to sectools validate.NewURLValidator; handle init errors gracefully
- Validate and normalize request/callback URLs with clear error paths
- Introduce ensureRetrier helper for consistent retry configuration
- Tests: add newTestURLValidator and update scheduler tests (TLS servers, allow
  IP/private/localhost cases)
- Docs: update README to document scheduler URL validation

build: add dependency github.com/hyp3rd/sectools v1.1.9 (go.mod/sum)
chore: bump BUF_VERSION to v1.64.0 in env and Makefile
- Add tests covering:
  - reject http URLs by default
  - allow http when URL validation is disabled
  - endAt in the past stops immediately
  - remove cancels scheduled job
  - non-retryable status handling
  - callback body size limit behavior
- Refactor tests:
  - introduce targetPath and callbackPath constants
  - centralize schedule error format via scheduleJobError
  - build URLs using server.URL + targetPath/callbackPath
- Docs: add README examples for relaxing/turning off URL validation

Rationale: strengthens coverage of scheduler guarantees (HTTPS-only by default, configurable validation, termination semantics, and callback payload handling) and documents configuration for future users.
@hyp3rd hyp3rd merged commit ebceda8 into main Jan 21, 2026
9 of 10 checks passed
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