-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] some minor fixes #201
Conversation
- introduce Exception instance for ParseAdvisoryError - display if parsing out of band git attributes failed
Left _ -> emptyOutOfBandAttributes | ||
liftIO (getAdvisoryGitInfo advisoryPath) >>= \case | ||
Left gitErr -> | ||
liftIO (hPutStrLn stderr ("obtaining out of band attributes failed: \n" <> explainGitError gitErr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May we return a validation error instead of a warning on the stderr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chesterton's fence: why's the error ignoed in the first place, are there valid reasons to not abort here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not, then this was an actual bug but it seems too obvious to be one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea is that we don't want to fail if there's no git information as there might still be one supplied by the advisory itself. I think this is an issue with the structure of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have decided to bubble the error up instead of using this oobValue
with optional fields. I think it was just not very fortunately designed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that looks reasonable to me. Though I worry this is a complicated API for downstream users, perhaps we could do instead:
- Make the oob attributes explicit in the advisory document, and/or
- Publish a static version of the advisories with the oob attributes pre resolved.
What do you think @frasertweedale ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Publishing a version with the oob pre resolved would be a good idea anyways. That would make testing without git possible and generally would allow distribution without git. I don’t think the interface for downstream users is more complicated now, tbh it was quite complicated with these fields that could independently be Nothing when in reality I don’t see a reason why they should be able to. Not attaching a reason for why the oob attributes being missing was problematic as well, imo, this caused the Git errors to never be shown.
something else I was wondering. Do we really want |
… it seems like this is an endeavour for another day, toml-parser doesn’t support it (though it should) |
dbf5de8
to
8e8b11e
Compare
I have refactored the out of band stuff such that we can bubble up information on why it failed. This is important if git doesn't work as expected. |
- OutOfBandAttributes now have two mandatory fields - the git error is bubbled up until it can be handled in validation
I can backport 4b and fe to the minor version if you don’t want breaking changes but I don’t know if it’d be too helpful. |
I believe this will resolve an issue that currently causes https://github.com/MangoIV/cabal-audit to break for me. Though @MangoIV can correct me if that is incorrect. |
Yes @frasertweedale already knows :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick note aside: I'm not a fan of BlockArguments
@MangoIV can you check whether forcing git date format fixes the issue please?
parseTime :: String -> Either GitError ZonedTime | ||
parseTime s = maybe (Left $ GitTimeParseError s) Right $ | ||
iso8601ParseM s | ||
<|> utcToZonedTime utc <$> iso8601ParseM s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it does preserve the date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just validated that the osv files are not changed by this PR with:
mkdir osvs
for i in $(find advisories/ -name "*.md" | grep -v reserved); do cabal run exe:hsec-tools -- osv $i > osvs/$(basename $i); done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not that obvious, we get a time and day without time zone, assuming UTC seems audacious.
IMO, we should rely only on UTCTime, enforcing it in the git command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, yes I'm on UTC. Then I remove my approval. Perhaps we could just parse an epoch timestamp if possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hsec-tools already does this several times (assuming UTC when there's not enough information) That's why I opened the issue about removing ZonedTime from hsec-tools. It makes stuff harder as well. It is however the correct time to assume, it's not wrong, it's just not semantically as nice. See #203 cc @frasertweedale who commented on #203
parseTime s = maybe (Left $ GitTimeParseError s) Right $ iso8601ParseM s | ||
parseTime :: String -> Either GitError ZonedTime | ||
parseTime s = maybe (Left $ GitTimeParseError s) Right $ | ||
iso8601ParseM s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should force the format at git level: https://stackoverflow.com/a/7651782
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to pass --date=local
and it didn't work. This is in general not really ideal, we shouldn't depend on the git installation if git itself doesn't guarantee a stable interface to these things and/ or this is not documented.
There's also haskell/time#257 which I don't know whether it's the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/MangoIV/cabal-audit/actions/runs/9321254777/job/25659857545
here's a run. the build step is Test git
which uses the date format local and it still outputs a non-zoned iso8601. I wouldn't have done the separate parse try without trying that first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume (read "guess") that it is valid to output a non-zoned iso8601 even with local
if the computer is itself in UTC
which is why I'm not sure whether parsing an unzoned time into a UTCTime
should just work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this, it seems to be the lesser bad solution we have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, setting it in git is a non-solution because it doesn't work. We have to do it like this, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, I thought that, requiring a ZonedTime from git wasn't working, requiring a UTCTime doesn't work either?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh but then we always lose zone information, what does that improve? should we do #203 then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frasertweedale was talking of a flag few minutes ago (at ZuriHac), maybe we can have a try
I have replaced ZonedTime with UTCTime; there's now not a single place where ZonedTime occurs anymore |
how do I check if the advisories are still valid btw? :3 |
don't wanna break your stuff :3 |
thank you for your review @blackheaven @TristanCacqueray <3 |
the CI handles it :) |
Thank you @MangoIV! Merging now. |
resolves #203
resolves #202
resolves #200
hsec-tools