git.iko.soy/rowtype-yoga/purescript-yoga-om-layer
on main help sign in
92 lines 2.3 kB history raw
1# Example Error Messages
3## Before: Only First Missing Dependency
5In our initial implementation, you would only see:
7```
8Custom error:
9 Missing required dependency!
10 The layer requires: "config"
11```
13You'd have to fix `config`, recompile, then see:
14```
15Missing required dependency!
16The layer requires: "logger"
17```
19And so on... one at a time.
21## After: Full Diff!
23Now you see everything at once:
25```purescript
26needsThree :: OmLayer
27 (config :: Config, logger :: Logger, database :: Database)
28 (cache :: Cache)
29 ()
31test = runLayer { logger: { log: \_ -> pure unit } } needsThree
32```
34Error shows **both** the specific problem AND the complete picture:
36```
37Custom error:
38 Missing required dependency!
40 The first missing field is:
41 "config"
43 The layer requires:
44 ( config :: { port :: Int }
45 , database :: { query :: String -> Effect (Array String) }
46 , logger :: { log :: String -> Effect Unit }
47 )
49 But you provided:
50 ( logger :: { log :: String -> Effect Unit }
51 )
52```
54Now you get:
55- ๐ŸŽฏ **Actionable**: "Fix `config` first" - specific field name
56- ๐Ÿ“‹ **Complete context**: Full diff of required vs provided
57- ๐Ÿ‘๏ธ **Visual comparison**: Instantly see:
58 - โœ… `logger` is provided
59 - โŒ `config` is missing
60 - โŒ `database` is missing
62**Best of both worlds**: Specific actionable error + full context to understand the complete situation!
64## How It Works
66The trick is to **thread the original `Row Type`s through the RowList recursion**:
68```purescript
69class CheckLabelExists
70 (label :: Symbol)
71 (ty :: Type)
72 (available :: RowList Type)
73 (requiredRow :: Row Type) -- โ† Thread through!
74 (availableRow :: Row Type) -- โ† Thread through!
75```
77When we hit the error case (missing label), we have both complete rows available to print:
79```purescript
80else instance checkLabelExistsNotFound ::
81 Fail
82 ( Above (Text "The layer requires: ")
83 (Above (Quote requiredRow) -- โ† Show complete required
84 (Above (Text "But you provided: ")
85 (Quote availableRow) -- โ† Show complete available
86 )
87 )
88 ) =>
89 CheckLabelExists label ty Nil requiredRow availableRow
90```
92This gives you a **full context diff** instead of just the first error!