Skip to content

fix(parser): panic when NewParser called with no fields#31

Merged
CybotTM merged 1 commit intomainfrom
fix/newparser-no-fields
Nov 26, 2025
Merged

fix(parser): panic when NewParser called with no fields#31
CybotTM merged 1 commit intomainfrom
fix/newparser-no-fields

Conversation

@CybotTM
Copy link
Member

@CybotTM CybotTM commented Nov 26, 2025

Summary

  • NewParser(0) now panics with "at least one field or Descriptor must be configured"
  • This prevents creating a parser that silently accepts empty/whitespace input and returns invalid schedules
  • A parser with only Descriptor flag is still valid as it can parse @descriptors

Problem

Previously NewParser(0).Parse(" ") would return a schedule using all default values instead of an error. This was misleading and could cause subtle bugs.

Upstream Reference

Addresses robfig#555 - Parser panics when called with timezone-only spec or missing fields.

Test plan

  • Test verifies NewParser(0) panics
  • Test verifies NewParser(Descriptor) is valid and can parse @daily
  • All existing tests continue to pass
  • Linter passes

Closes #21

NewParser(0) previously created a parser that silently accepted empty
input and returned a schedule with all default values. Now it panics
with a clear message, matching the existing pattern for invalid
configuration (multiple optionals).

A parser with only Descriptor flag is still valid as it can parse
@descriptors like @daily, @hourly, etc.

Closes #21
@CybotTM CybotTM merged commit acf5afc into main Nov 26, 2025
13 checks passed
@CybotTM CybotTM deleted the fix/newparser-no-fields branch November 26, 2025 11:40
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.

fix: Handle panic in NewParser with no fields

1 participant