Skip to content

Fix #11: reject quoted timestamps instead of silently parsing as null - #124

Merged
andreabedini merged 1 commit into
mainfrom
improve-parsing
May 29, 2026
Merged

Fix #11: reject quoted timestamps instead of silently parsing as null#124
andreabedini merged 1 commit into
mainfrom
improve-parsing

Conversation

@andreabedini

Copy link
Copy Markdown
Collaborator

Fixes #11.

Problem

If a user writes a quoted timestamp in meta.toml:

timestamp = '2022-03-29T06:19:50+00:00'

instead of the correct bare TOML datetime:

timestamp = 2022-03-29T06:19:50+00:00

the old code silently parsed it as Nothing (because Toml.dioptional swallows all failures, not just missing-key ones). The user ended up with a broken index — no package timestamp, broken index-state support — with no error or warning.

Fix

Replaces Toml.dioptional (timeCodec "timestamp") with a handrolled optionalTimeCodec that distinguishes between:

  • key absent → Nothing (fine)
  • key present but wrong type → parse error (previously silently swallowed)

The underlying matchMaybe helper looks up the key first; if it's present it applies the BiMap and surfaces any type mismatch as an error. This is the approach discussed in the tomland issue and previously explored in #57.

The error message users now see is clear and actionable:

BiMap error in key 'timestamp': Invalid constructor
  * Expected: TZoned
  * Actual:   Text "2022-03-29T06:19:50+00:00"

Changes

  • app/Foliage/Meta.hs: add optionalTimeCodec + matchMaybe, use in sourceMetaCodec
  • foliage.cabal: add mtl, unordered-containers (needed by the new codec)
  • tests/Tests.hs: new test case verifying foliage build fails on a quoted timestamp
  • tests/fixtures/bad-timestamp/: minimal fixture for the new test

Copilot AI review requested due to automatic review settings May 18, 2026 04:26

Copilot AI left a comment

Copy link
Copy Markdown

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 addresses quoted TOML timestamps being silently treated as missing metadata, so invalid meta.toml files fail instead of producing repositories without package timestamps.

Changes:

  • Adds a custom optional timestamp codec that distinguishes missing keys from type mismatches.
  • Adds a regression test and fixture for quoted timestamp rejection.
  • Updates executable dependencies and root-only ignore patterns for generated directories.

Reviewed changes

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

Show a summary per file
File Description
app/Foliage/Meta.hs Replaces optional timestamp parsing with a custom codec that errors on invalid timestamp values.
tests/Tests.hs Adds a build-failure regression test for quoted timestamps.
tests/fixtures/bad-timestamp/_sources/pkg-a/1.0.0.0/meta.toml Adds an invalid quoted timestamp fixture.
foliage.cabal Adds dependencies required by the custom codec implementation.
.gitignore Attempts to anchor generated directory ignore patterns to the repository root.

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

Comment thread tests/Tests.hs
Comment thread foliage.cabal Outdated
Comment thread app/Foliage/Meta.hs Outdated
Comment thread tests/Tests.hs
@andreabedini
andreabedini force-pushed the improve-parsing branch 2 times, most recently from fb69a9f to c4c0bdf Compare May 18, 2026 05:19
@andreabedini
andreabedini requested a review from neilmayhew May 18, 2026 05:25
@andreabedini
andreabedini enabled auto-merge (rebase) May 18, 2026 05:25
@andreabedini
andreabedini force-pushed the improve-parsing branch 3 times, most recently from 9da7c7f to 38daf05 Compare May 21, 2026 06:41
@neilmayhew

Copy link
Copy Markdown
Contributor

Sorry, I didn't see the review request until now. I'll take a look tomorrow.

@neilmayhew neilmayhew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice to have this fixed!

Comment thread tests/Tests.hs
testCaseSteps "rejects quoted timestamp in meta.toml" $ \step ->
inTemporaryDirectoryWithFixture "tests/fixtures/bad-timestamp" $ do
step "Building repository (expecting failure)"
result <- try @SomeException (callCommand "foliage build --no-signatures")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
result <- try @SomeException (callCommand "foliage build --no-signatures")
result <- try @IOError (callCommand "foliage build --no-signatures")

Pedantic, I know, but SomeException always looks like a code smell to me,

Even better would be to use readProcessWithExitCode and check the exit code, and maybe even the stderr, but that's a lot of trouble for not a lot of gain.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I forgot about auto-merge being enabled!

Oh, well, it was fine anyway.

@andreabedini
andreabedini merged commit fb6b77f into main May 29, 2026
3 checks passed
@andreabedini
andreabedini deleted the improve-parsing branch May 29, 2026 04:11
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.

Improve parsing

3 participants