Skip to content

Commit 5cf3853

Browse files
committed
agent: drop unused FromField SimplexNameInfo
The instance landed in the previous commit alongside ToField but has zero consumers in either repo — chat-side row decoders use the soft-degradation `decodeSimplexName` helper at the tuple level, never this instance. `fromTextField_` raises ConversionFailed on parse failure, which doesn't compose with the chat policy. Keep ToField (used by parameter binding in name lookups). Leave a comment explaining why FromField is absent so a future contributor doesn't reintroduce it without thinking about the decode policy.
1 parent e5b083c commit 5cf3853

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/Simplex/Messaging/SimplexName.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import Data.Functor (($>))
2828
import Data.Text (Text)
2929
import qualified Data.Text as T
3030
import Data.Text.Encoding (decodeLatin1, encodeUtf8)
31-
import Simplex.Messaging.Agent.Store.DB (FromField (..), ToField (..), fromTextField_)
31+
import Simplex.Messaging.Agent.Store.DB (ToField (..))
3232
import Simplex.Messaging.Encoding.String
3333
import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, enumJSON)
34-
import Simplex.Messaging.Util (eitherToMaybe, safeDecodeUtf8, (<$?>))
34+
import Simplex.Messaging.Util (safeDecodeUtf8, (<$?>))
3535

3636
data SimplexNameInfo = SimplexNameInfo
3737
{ nameType :: SimplexNameType,
@@ -124,10 +124,13 @@ shortNameInfoStr = \case
124124
NTPublicGroup -> "#"
125125
NTContact -> "@"
126126

127+
-- | Stored as TEXT. The matching `FromField` instance is intentionally not
128+
-- defined: existing consumers want soft-decode semantics (parse failure
129+
-- degrades to `Nothing` rather than failing the row), which doesn't
130+
-- compose with `fromTextField_`. Add a `FromField` instance here only
131+
-- when a consumer wants the row-fail behaviour and document the divide.
127132
instance ToField SimplexNameInfo where toField = toField . decodeLatin1 . strEncode
128133

129-
instance FromField SimplexNameInfo where fromField = fromTextField_ $ eitherToMaybe . strDecode . encodeUtf8
130-
131134
$(J.deriveJSON (enumJSON $ dropPrefix "TLD") ''SimplexTLD)
132135

133136
$(J.deriveJSON (enumJSON $ dropPrefix "NT") ''SimplexNameType)

0 commit comments

Comments
 (0)