-
Notifications
You must be signed in to change notification settings - Fork 73
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 confused config keys #282
Fix confused config keys #282
Conversation
The fields of KeterConfig were being parsed from Yaml with a "flipped string constants" mistake: * kconfigUnknownHostResponse -- from "missing-host-response-file" * kconfigMissingHostResponse -- from "unknown-host-response-file" Fix that; use a speck of typelevel spice to showcase "how not to" fall victim to this class of mistakes again, if desired. The Tagged helper is: * zero-cost; * simple; * easy to use; * attaches a constant string to a type, and transparently tracks it for as long as you allow it to -- e.g. in this case, from KeterConfig data-decl all the way until readFile calls.
src/Keter/Config/V10.hs
Outdated
<*> o .:? "missing-host-response-file" | ||
<*> o .:? "unknown-host-response-file" | ||
<*> o .:? "proxy-exception-response-file" | ||
<*> inferOptKeyFromTaggedType o | ||
<*> inferOptKeyFromTaggedType o | ||
<*> inferOptKeyFromTaggedType o |
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.
Root cause of the mismatch is here... 👀 wrong order:
<*> o .:? "missing-host-response-file"
<*> o .:? "unknown-host-response-file"
this is flipped cf. the fields of KeterConfig
:
, kconfigUnknownHostResponse :: !(Maybe F.FilePath)
, kconfigMissingHostResponse :: !(Maybe F.FilePath)
Tagged
allows to avoid this pitfall completely.
Hi 👋 could you fix the bug without introducing a dependency? |
tagged is very small, and nearly 0-deps itself (it does pull in a few deps optionally with some older GHC versions and non-default flags; even GHC 7 is supported). Reimplementing it is a matter of a 1-page module; sure can do... but do you really want this code in keter? |
With E.g. you'd get errors like this:
|
is there a way you can think of implementing this without using |
no. it's how you get type-reflected values back to value level. why? |
If you dislike the "typelevel spice" — there's ofcourse much simpler fix: just flip back the constants into correct order. six lines of diff if I'm counting correctly Just showcasing how in principle, it's possible to do better than that 🤷 |
please do the simpel fix, I've seen enough of typelevel spice in haskell to know I don't want any of it in production code, it's fine for art 😀 your change from error to warning is justified I suppose. I wasn't sure what the right behavior was, erroring or warning. |
please add a note to the changelog as well |
Agda forces you into the "correct by construction" cage; while Haskell allows to put (or not!) just one finger into it 😆 See the commit just pushed — reimplemented the dependency in 2 lines; it's really that simple.
Yes, it'll save deployment roundtrips with, said politely, "messed up" infrastructure, one that keeps hundreds of copies of those configs (per every running keter instance). The fallback is already there, so why not use it, right? |
Please drop the tagged idea. 😅 I understand you put effort into figuring out how to do that, |
Okay; another problem which Tagged has helped with, now resurfaces: not only the ordering in Lines 102 to 107 in 709bbc3
which obviously is error-prone (another "just has to be right"); also inflates line lengths.
@jappeace that looks good to you? I disagree, but doesn't matter, you're the one requesting changes here 🥲 I'm happy to oblige. |
OMG wait... I've done the same mistake myself 🤣 That's what I'm saying — it's way too easy to mess up!.. I know to trust myself, but humans get tired, distracted, lose concentration, etc... IMO there's no harm in buying a little transparent insurance from a good type-system. |
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 for your changes. I'm sorry but I don't think this code changes often enough to justify an abstraction like that. We'll keep it simple, even though it's a little brittle.
If you care a lot about correct config loading I think the best thing to do is write a test (which I'd love to see! This project has far too few tests)
don't forget to update the changelog
Done. Changelog opened for 2.1.3 |
thanks for your contribution |
Hi again @jappeace 👋
I'm updating a vendor-fork of keter onto version 2; this piece of feedback bubbled up from testing:
(in Keter/Proxy.hs)
Far from a huge bug, it doesn't make any difference for us (setting them both to the same .html stub anyway) — yet, I'm guessing it's probably unintentional.
Most interesting commit to review is the 3rd one, 2f89797, let me quote the commit message:
Please review & merge.