Skip to content

Commit bf0b196

Browse files
authored
Merge pull request #2260 from digitallyinduced/add-werror-incomplete-patterns
Add -Werror=incomplete-patterns across all packages
2 parents 3d850e4 + b6293b2 commit bf0b196

File tree

49 files changed

+126
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+126
-6
lines changed

.ghci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
:set -Wno-unsafe -Wno-name-shadowing -Wno-monomorphism-restriction -Wno-safe -Wno-missing-local-signatures -Wno-missing-home-modules
4848
:set -Werror=missing-fields
49-
:set -fwarn-incomplete-patterns
49+
:set -Werror=incomplete-patterns
5050
:set -Wno-ambiguous-fields
5151
:set -fprefer-byte-code
5252
:set -fbyte-code-and-object-code

ihp-context/ihp-context.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ common shared-properties
3232
, ImplicitParams
3333
, BlockArguments
3434
, LambdaCase
35+
ghc-options: -Werror=incomplete-patterns
3536

3637
library
3738
import: shared-properties

ihp-datasync-typescript/ihp-datasync-typescript.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ common shared-properties
3636
, LambdaCase
3737
, TemplateHaskell
3838
, OverloadedRecordDot
39+
ghc-options: -Werror=incomplete-patterns
3940

4041
library
4142
import: shared-properties

ihp-datasync/IHP/DataSync/ChangeNotifications.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ instance FromJSON ChangeSet where
163163
case UUID.fromText id of
164164
Just largePgNotificationId -> pure ExternalChangeSet { largePgNotificationId }
165165
Nothing -> fail "Invalid UUID"
166+
parseJSON invalid = fail $ cs ("Expected Array or String for ChangeSet, got: " <> tshow invalid)
166167

167168
instance FromJSON Change where
168169
parseJSON = withObject "Change" $ \values -> do

ihp-datasync/IHP/DataSync/ControllerImpl.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ buildMessageHandler ensureRLSEnabled installTableChangeTriggers sendJSON handleC
196196
if isRecordInResultSet
197197
then sendJSON DidUpdate { subscriptionId, id, changeSet = changesToValue (renamer tableName) changes }
198198
else sendJSON DidDelete { subscriptionId, id }
199+
ChangeNotifications.DidUpdateLarge { id, payloadId } -> do
200+
isWatchingRecord <- Set.member id <$> readIORef watchedRecordIdsRef
201+
when isWatchingRecord do
202+
[(PG.Only isRecordInResultSet)] <- sqlQueryWithRLS ("SELECT EXISTS(SELECT * FROM (" <> theQuery <> ") AS records WHERE records.id = ? LIMIT 1)") (theParams <> [PG.toField id])
203+
204+
changes <- ChangeNotifications.retrieveChanges (ChangeNotifications.ExternalChangeSet { largePgNotificationId = payloadId })
205+
if isRecordInResultSet
206+
then sendJSON DidUpdate { subscriptionId, id, changeSet = changesToValue (renamer tableName) changes }
207+
else sendJSON DidDelete { subscriptionId, id }
199208
ChangeNotifications.DidDelete { id } -> do
200209
-- Only send the notifcation if the deleted record was part of the initial
201210
-- results set

ihp-datasync/IHP/DataSync/DynamicQuery.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ data SelectedColumns
9999

100100
instance FromJSON ByteString where
101101
parseJSON (String v) = pure $ cs v
102+
parseJSON invalid = fail $ cs ("Expected String for ByteString, got: " <> tshow invalid)
102103

103104
instance FromJSON PG.Action where
104105
parseJSON (String v) = pure (PG.Escape (cs v))
106+
parseJSON invalid = fail $ cs ("Expected String for PG.Action, got: " <> tshow invalid)
105107

106108
instance {-# OVERLAPS #-} ToJSON [Field] where
107109
toJSON fields = object (map (\Field { fieldName, fieldValue } -> (cs fieldName) .= (toJSON fieldValue)) fields)
@@ -184,6 +186,7 @@ transformColumnNamesToFieldNames (Object hashMap) =
184186
|> Aeson.toText
185187
|> function
186188
|> Aeson.fromText
189+
transformColumnNamesToFieldNames otherwise = otherwise
187190

188191

189192
$(deriveFromJSON defaultOptions ''FunctionCall)

ihp-datasync/IHP/DataSync/DynamicQueryCompiler.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,6 @@ instance PG.ToField DynamicValue where
186186
toField (UUIDValue uuid) = PG.toField uuid
187187
toField (DateTimeValue utcTime) = PG.toField utcTime
188188
toField (PointValue point) = PG.toField point
189+
toField (IntervalValue interval) = PG.toField interval
189190
toField (ArrayValue values) = PG.toField (PG.PGArray values)
190191
toField Null = PG.toField PG.Null

ihp-datasync/IHP/DataSync/REST/Controller.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ instance (
8787
result :: [[Field]] <- sqlQueryWithRLS query params
8888
renderJson result
8989

90-
90+
_ -> error "Expected JSON object or array"
9191

9292
action UpdateRecordAction { table, id } = do
9393
ensureRLSEnabled table
9494

9595
let payload = requestBodyJSON
9696
|> \case
9797
Object hashMap -> hashMap
98+
_ -> error "Expected JSON object"
9899

99100
let columns = payload
100101
|> Aeson.keys
@@ -147,6 +148,9 @@ instance (
147148
148149
renderJson result
149150
151+
action GraphQLQueryAction = do
152+
error "GraphQLQueryAction is handled by the GraphQL middleware"
153+
150154
buildDynamicQueryFromRequest table = DynamicSQLQuery
151155
{ table
152156
, selectedColumns = paramOrDefault SelectAll "fields"
@@ -170,6 +174,7 @@ instance ParamReader OrderByClause where
170174
orderByDirection <- parseOrder order
171175
pure OrderByClause { orderByColumn, orderByDirection }
172176
[orderByColumn] -> pure OrderByClause { orderByColumn, orderByDirection = Asc }
177+
_ -> Left "Invalid order by clause"
173178
where
174179
parseOrder "asc" = Right Asc
175180
parseOrder "desc" = Right Desc
@@ -184,10 +189,15 @@ instance ToJSON PG.SqlError where
184189
]
185190
where
186191
fieldValueToJSON (IntValue value) = toJSON value
192+
fieldValueToJSON (DoubleValue value) = toJSON value
187193
fieldValueToJSON (TextValue value) = toJSON value
188194
fieldValueToJSON (BoolValue value) = toJSON value
189195
fieldValueToJSON (UUIDValue value) = toJSON value
190196
fieldValueToJSON (DateTimeValue value) = toJSON value
197+
fieldValueToJSON (PointValue value) = toJSON value
198+
fieldValueToJSON (IntervalValue value) = toJSON value
199+
fieldValueToJSON (ArrayValue value) = toJSON value
200+
fieldValueToJSON IHP.DataSync.DynamicQuery.Null = toJSON Data.Aeson.Null
191201
192202
instance ToJSON EnhancedSqlError where
193203
toJSON EnhancedSqlError { sqlError } = toJSON sqlError

ihp-datasync/IHP/DataSync/REST/Routes.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ instance CanRoute ApiController where
3030
PATCH -> pure UpdateRecordAction { table, id }
3131
GET -> pure ShowRecordAction { table, id }
3232
DELETE -> pure DeleteRecordAction { table, id }
33+
_ -> error "updateOrDeleteRecordAction: unsupported method"
3334

3435
listRecordsAction table = do
3536
endOfInput
3637
method <- getMethod
3738
case method of
3839
GET -> pure ListRecordsAction { table }
40+
_ -> error "listRecordsAction: unsupported method"
3941

4042
crud = do
4143
table <- parseText
@@ -47,4 +49,6 @@ instance HasPath ApiController where
4749
pathTo CreateRecordAction { table } = "/api/" <> table
4850
pathTo UpdateRecordAction { table, id } = "/api/" <> table <> "/" <> tshow id
4951
pathTo DeleteRecordAction { table, id } = "/api/" <> table <> "/" <> tshow id
52+
pathTo ShowRecordAction { table, id } = "/api/" <> table <> "/" <> tshow id
53+
pathTo ListRecordsAction { table } = "/api/" <> table
5054
pathTo GraphQLQueryAction = "/api/graphql"

ihp-datasync/ihp-datasync.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ common shared-properties
8989
-Wmissed-specialisations
9090
-Wall-missed-specialisations
9191
-Wno-ambiguous-fields
92+
-Werror=incomplete-patterns
9293
else
9394
ghc-options:
9495
-fstatic-argument-transformation
@@ -102,6 +103,7 @@ common shared-properties
102103
-Wmissed-specialisations
103104
-Wall-missed-specialisations
104105
-Wno-ambiguous-fields
106+
-Werror=incomplete-patterns
105107

106108
library
107109
import: shared-properties

0 commit comments

Comments
 (0)