-
-
Notifications
You must be signed in to change notification settings - Fork 10
Description
What's the problem?
When you run neo build or neo shell with an invalid project name, the CLI might crash instead of giving you a helpful error message.
We're using Maybe.getOrDie in our code, which is basically saying "this should work, and if it doesn't... 💥 crash!" That's fine for prototyping, but not great when someone's trying to build their project at 10 PM.
Where this happens
Both commands have this risky code:
let cabalFileName =
[fmt|#{projectName}.cabal|]
|> Path.fromText
|> Maybe.getOrDie -- 😬 This could crash!Found in:
cli/src/Neo/Build.hs(line 36)cli/src/Neo/Shell.hs(line 36)
Why we should fix this
Imagine you're Jess, our target developer:
- It's late, you're tired
- You accidentally type
neo build "my project"(with a space) - Instead of a helpful message, the CLI crashes
- You spend 20 minutes debugging instead of building
We can do better!
How to fix it
We have a few options - pick the one that feels right:
Option A: Quick fix (30 minutes)
Just handle the error gracefully:
-- Instead of crashing, show a helpful message
cabalFileName <- case Path.fromText [fmt|#{projectName}.cabal|] of
Nothing -> Task.throw (Error.InvalidProjectName
"Project names can't contain spaces or special characters. Try: my-project")
Just path -> Task.yield pathOption B: Validate early (1 hour)
Check the project name when we first read the configuration:
-- In project configuration parsing
validateProjectName :: Text -> Task Error ProjectName
validateProjectName name =
if hasValidChars name
then Task.succeed (ProjectName name)
else Task.fail "Project name must contain only letters, numbers, and hyphens"Option C: Make it impossible to fail (2-3 hours)
Create a smart constructor that guarantees valid paths at compile time. This is more advanced but prevents the issue entirely.
Getting started
Time estimate: 30 minutes - 2 hours (depending on approach)
Perfect for: Someone who wants to improve error handling and make the CLI more user-friendly
Steps:
- Try to reproduce the crash (create a project with spaces in the name)
- Pick your approach (start with Option A if unsure!)
- Fix it in both files
- Test that invalid names now show helpful errors
- Make sure valid names still work!
Testing your fix
Before:
$ neo build "my cool project"
[CRASH: getOrDie called on Nothing] # 😱After:
$ neo build "my cool project"
Error: Invalid project name "my cool project"
Project names can only contain letters, numbers, and hyphens.
Try: my-cool-projectNeed help?
This is about making NeoHaskell friendlier when things go wrong. If you're stuck for more than 15 minutes, jump in our [Discord](link-to-discord) - we've all been bitten by getOrDie before!
Context: Found during our haskell.nix migration (PR #199). The TODOs in the code are calling out to be fixed!