fix(scheduler): guard nil errors; drain request body; docs/tests#20
Merged
fix(scheduler): guard nil errors; drain request body; docs/tests#20
Conversation
Owner
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).
Contributor
There was a problem hiding this comment.
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
readBodyto properly handle successful body draining without returning spurious errors - Added
isNilErrorhelper 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.