-
Notifications
You must be signed in to change notification settings - Fork 632
Conversation
f8351c9
to
dc6670e
Compare
fail "Incorrect JSON encoding for JSONValidationError" | ||
|
||
parseJSON invalid = | ||
typeMismatch "JSONValidationError" invalid |
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.
No usage of generics here, to have consistent approach with the work recently done on Errors.
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.
Note that withObject
does the pattern match/note dance for you
import qualified Pos.Core.Attributes as Core | ||
import qualified Pos.Crypto.Hashing as Crypto | ||
import Pos.Util.Util (aesonError) | ||
|
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.
Everything moved to V1/Types.hs
dc6670e
to
8965dd4
Compare
import Data.List ((!!)) | ||
import Pos.Util.Util (aesonError) | ||
|
||
-- |
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.
Now that WalletError
JSON instances are defined by hand, we don't need all the sop-generic stuff. I'd be more than happy to re-introduce generics here if we can find a way to do so without relying on partial field accessors.
V0.SignedTxInvalidSignature txt -> | ||
SignedTxSubmitError $ sformat build (V0.SignedTxInvalidSignature txt) | ||
V0.GeneralTxError txt -> | ||
UnknownError txt |
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.
Move from API/V1/Errors.hs
because used only here.
fail "Incorrect JSON encoding for MigrationError" | ||
|
||
parseJSON invalid = | ||
typeMismatch "MigrationError" invalid |
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.
idem JSONValidationError
, mkRow errToDescription AddressNotFound | ||
, mkRow errToDescription $ MissingRequiredParams (("wallet_id", "walletId") :| []) | ||
, mkRow errToDescription $ WalletIsNotReadyToProcessPayments sampleSyncProgress | ||
, mkRow errToDescription $ NodeIsStillSyncing (mkSyncPercentage 42) |
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.
Meh. This lacks some of the available errors. Would be nice to have a generic way to generate those, or if not, something that will crash at runtime upon starting if one of them is missing though lazyness doesn't serve us well 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.
TODO
quantity <- parseJSON quantityO | ||
return . NodeIsStillSyncing $ mkSyncPercentage quantity | ||
| otherwise = fail "Incorrect JSON encoding for WalletError" | ||
parseJSON invalid = typeMismatch "WalletError" invalid |
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.
The only changes compare to the base branch here are:
- Dropped usage of
Pos.Util.Util.aesonError
in favor offail
which is doing pretty-much the same thing without 454325 level of indirections. - Remove the MigrationError & JSONValidationError which are now standalone types.
wallet-new/test.md
Outdated
sklfjs fsdkfjsd fsdkfjsdfksdf sdfkljsdfs dfksdjfsdfsd fsldfmsdf sfksdflksdf | ||
sdfksdjfklsd fsdkfjsdklfs fsdkfsdkfsd fksdjfsdf flksjfksd fsfkjsdfkd fkdjopqpw | ||
poxvn slakfps masmpxx lsfjn dfjdj aod aal do akdnf aod da pd diq didbdh die oa | ||
aidbna dla sja da diand saa dsoa aodjs akisopa dka' |
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.
Whoops.
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.
TODO
55fe38f
to
63ae68a
Compare
I have "reviewed" it by implementing all the changes I would have done. |
err <- diag .: "validationError" | ||
pure $ JSONValidationFailed err | ||
_ -> | ||
fail "Incorrect JSON encoding for JSONValidationError" |
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.
neat 👌
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.
LGTM!
* [CO-319] Fix account index swagger example * [CO-319] Add roundtrip tests * [CO-319] Fix recursive buildable instances * [CO-319] Use strongly typed error * [CO-319] Remove duplication in 'renderAccountIndexError' * [CO-319] Distangle V1/Errors This makes it now possible to import V1/Errors from the V1/Types module and leverage errors from this module. One thing is still unclear to me: Why Errors isn't defined in V1/Types already? There's a circular dependency between V1/Response and V1/Types if we go this way, as well as between V1/Migration and V1/Types. Nevertheless, it would make sense to have three data-types here: - WalletError (defined in V1/Types) - MigrationError (defined in V1/Types) - JSONParsingError (defined in Response) This way, we could remove the conflicting constructor from WalletError and remove the need for an extra module here. It will also makes thing clearer * [CO-319] Make V1/Error part of V1/Types To realize this, we had to extract JSONValidationFailed and MigrationFailed constructor from WalletError. They're now defined as constructor in different data-types (resp. JSONValidationError and MigrationError). * [CO-319] Solve rebase conflicts * [CO-319] Correctly format (jsend) newtype errors This is rather ugly and could probably be achieved nicely with a better understanding of the Generics.SOP library. As far as I could tell, there's no easy way to retrieve 'Tag' for single constructor (cf: 'For a datatype with a single constructor we do not need to tag values with their constructor; but for a datatype with multiple constructors we do. ')
We used to rely on this code solely for 'WalletError' instances. Though, we now declare those instances by hand using manual encoding. We might want to re-introduce generics is possible in the future. Note that we switch for a manual implementation because the current generics implementation relied on partial field accessors in the underlying types which we try to avoid. Another approach using generics without the need for partial field accessors would make everyone happier
7c94a28
to
72a608e
Compare
gDiagnosticToJSON k (K1 c) = object [ k .= c ] | ||
|
||
instance GDiagnosticToJSON U1 where | ||
gDiagnosticToJSON _ _ = object mempty |
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.
-> Declare (Definitions Schema) NamedSchema | ||
fromExampleJSON (_ :: proxy a) = do | ||
let (randomSample :: a) = genExample | ||
return $ NamedSchema (Just $ fromString $ show $ typeOf randomSample) (sketchSchema randomSample) |
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.
Moved into /Swagger/Example.hs
Core.mkAttributes $ Core.AddrAttributes Nothing Core.BootstrapEraDistr | ||
, Core.addrType = | ||
Core.ATPubKey | ||
} |
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 need to define this as a proper Example
pure $ SyncProgress | ||
(mkEstimatedCompletionTime estCompT) | ||
(mkSyncThroughput $ BlockCount blockCount) | ||
(mkSyncPercentage pct) |
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.
This was removed in favor of proper Arbitrary
instances. We were using Arbitrary
instances as Example
and defining these Gen whatever
to generate actual arbitrary data. Non-sense.
roundTripWalletError :: Property | ||
roundTripWalletError = | ||
eachOf 5000 genWalletError roundTripsAesonShow | ||
|
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.
Duplicate with tests in MarshalingSpec
72a608e
to
9b6e6a5
Compare
- This put the lights on a few breaking changes - 'NodeIsStillSyncing' error is now properly serialized to a JSend structure (was raw diagnostic before that) - 'WalletIsNotReadyToProcess' error is now properly serialized to a JSend structure - 'WalletAlreadyExists' error now contains the underlying wallet Id - I've extended the golden test suite with all (rather) recently introduced errors - Remove the 'WalletNewGen' in favor of a proper 'Arbitrary' instance defined in API/Types and the round-trip tests defined in MarshalingSpec - Aligned a couple of sample / example references, there's work to do on many types though
Turns out that some of them were actually wrongly migrated (and therefore, fixing them to what they ought to be isn't a breaking change as mentioned before. This concerns the NodeIsStillSyncing and WalletIsNotReadyToProcessPayment branches). This rewrite also makes thing more readable, and now I just want to refactor that to use generics.....
This is done through the combination of 'SOP.Generic', 'Generic' and 'HasDiagnostic' classe. Basically, what we miss from the old implementation are the names of all the partial reccord fields that were used to wrap the diagnostic part of the JSEnd response. These names are now provided by the 'HasDiagnostic' class that need to be implemented for each JSEnd error. From there, we provide two generic functions to convert a type 'a' to a JSON value and respectively, to parse any value to a type a. The main trick for the parsing is to leverage the 'Generic' instance and to construct a JSON value as Aeson would have serialized it in a first place. The serialization becomes quite straighforward once we can serialize the diagnostic which is done via an internal Generic class, working with a few type representations (not all, we don't need them). This approach is much more readable and maintainable than previously and will save us some errors due to typos or wrong formatting.
9b6e6a5
to
4bb60d3
Compare
4bb60d3
to
e7f76f5
Compare
Description
I've resurrected this branch from the abyss.
In theory, everything in there have been already reviewed but the rebase took me a few hours to complete with quite a lot of conflicts. @parsonsmatt, I'll have an extra look at the github diff, but I'd appreciate you have one too :)
Linked issue
[CBR-26]
Type of change
Developer checklist
Testing checklist
QA Steps
Screenshots (if available)