Skip to content

ntptime: Add module-specific exception types. - #1181

Open
Zosili wants to merge 1 commit into
micropython:masterfrom
Zosili:ntptime-exceptions
Open

Zosili wants to merge 1 commit into
micropython:masterfrom
Zosili:ntptime-exceptions

Conversation

@Zosili

@Zosili Zosili commented Nov 24, 2026

Copy link
Copy Markdown

Closes #1180.

time() raised a bare Exception when the platform epoch is neither 1970 nor
2000, and OSError(-1) when the server sends a short reply or a reply with a
zero stratum/timestamp, so callers could not tell these apart from unrelated
errors.

  • NTPError for the malformed-reply cases. It subclasses OSError, so existing
    except OSError handlers keep working.
  • UnsupportedEpochError for the epoch case.

test_ntptime.py gains two tests: one that checks the raised error is an
NTPError and still an OSError, and one that patches gmtime to return a
2010 epoch and expects UnsupportedEpochError. The existing tests still pass,
and the manifest version is bumped to 0.3.0 for the added API.

time() raised a bare Exception for an unsupported platform epoch and
OSError(-1) for a malformed reply, so callers had no way to tell these
apart from unrelated failures.

Add NTPError, which inherits from OSError so existing except OSError
handlers keep working, and UnsupportedEpochError for the epoch case.
Both are covered by the new tests in test_ntptime.py.

Signed-off-by: Zosili <zhx1005427725@outlook.com>
@Zosili
Zosili force-pushed the ntptime-exceptions branch from 1981c66 to 8404b16 Compare November 24, 2026 11:58
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.

ntptime has no custom exception type

1 participant