-
Notifications
You must be signed in to change notification settings - Fork 5
Allow running the project #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||||||||||
module Neo.Run ( | ||||||||||||||||||||||||||||||||||||||||||||
handle, | ||||||||||||||||||||||||||||||||||||||||||||
Error (..), | ||||||||||||||||||||||||||||||||||||||||||||
) where | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
import Array qualified | ||||||||||||||||||||||||||||||||||||||||||||
import Neo.Core | ||||||||||||||||||||||||||||||||||||||||||||
import Subprocess qualified | ||||||||||||||||||||||||||||||||||||||||||||
import Task qualified | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
data Error | ||||||||||||||||||||||||||||||||||||||||||||
= NixFileError | ||||||||||||||||||||||||||||||||||||||||||||
| CabalFileError | ||||||||||||||||||||||||||||||||||||||||||||
| CustomError Text | ||||||||||||||||||||||||||||||||||||||||||||
deriving (Show) | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+12
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) OBSERVE THE UNUSED ERROR VARIANTS WITH OMNISCIENT EYES! I notice that If these are intended for future use, consider adding a comment to indicate their purpose. If not needed, I command thee to simplify: data Error
- = NixFileError
- | CabalFileError
= CustomError Text
deriving (Show) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
handle :: ProjectConfiguration -> Task Error Unit | ||||||||||||||||||||||||||||||||||||||||||||
handle config = do | ||||||||||||||||||||||||||||||||||||||||||||
let projectName = config.name | ||||||||||||||||||||||||||||||||||||||||||||
let rootFolder = [path|nhout|] | ||||||||||||||||||||||||||||||||||||||||||||
completion <- | ||||||||||||||||||||||||||||||||||||||||||||
Subprocess.openInherit [fmt|./result/bin/{projectName}|] (Array.fromLinkedList []) rootFolder Subprocess.InheritBOTH | ||||||||||||||||||||||||||||||||||||||||||||
if completion.exitCode != 0 | ||||||||||||||||||||||||||||||||||||||||||||
then errorOut completion.stderr | ||||||||||||||||||||||||||||||||||||||||||||
else print completion.stdout | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+19
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) THE PATH IS HARDCODED, MORTAL! CONSIDER A MORE FLEXIBLE APPROACH! The path
handle :: ProjectConfiguration -> Task Error Unit
handle config = do
let projectName = config.name
let rootFolder = [path|nhout|]
+ let binaryPath = [fmt|./result/bin/{projectName}|]
+ binaryExists <- File.exists binaryPath |> Task.mapError (\_ -> CustomError "Could not check if binary exists")
+ unless binaryExists (Task.throw (CustomError [fmt|Binary not found at {binaryPath}. Ensure the project was built successfully.|]))
completion <-
- Subprocess.openInherit [fmt|./result/bin/{projectName}|] (Array.fromLinkedList []) rootFolder Subprocess.InheritBOTH
+ Subprocess.openInherit binaryPath (Array.fromLinkedList []) rootFolder Subprocess.InheritBOTH
if completion.exitCode != 0
then errorOut completion.stderr
else print completion.stdout 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
errorOut :: Text -> Task Error _ | ||||||||||||||||||||||||||||||||||||||||||||
errorOut err = | ||||||||||||||||||||||||||||||||||||||||||||
[fmt|Oops running failed: | ||||||||||||||||||||||||||||||||||||||||||||
{err}|] | ||||||||||||||||||||||||||||||||||||||||||||
|> CustomError | ||||||||||||||||||||||||||||||||||||||||||||
|> Task.throw | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+30
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) ENHANCE THY ERROR MESSAGES WITH DIVINE CLARITY! The error message could be more illuminating for your followers. Consider providing more specific guidance on potential solutions. errorOut :: Text -> Task Error _
errorOut err =
- [fmt|Oops running failed:
+ [fmt|The command failed to run with exit code:
{err}|]
+ |> \message -> [fmt|{message}
+ Potential solutions:
+ - Check if the binary was compiled correctly
+ - Ensure all required dependencies are available
+ - Verify the command line arguments if any|]
|> CustomError
|> Task.throw 📝 Committable suggestion
Suggested change
|
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.
🧹 Nitpick (assertive)
CONSIDER A MORE EXPLICIT BUILD-THEN-RUN FLOW!
The current implementation always executes
Build.handle
beforeRun.handle
which is logically sound, but could benefit from more explicit error handling between these steps.Consider this more explicit approach:
This approach makes it clear that the run step only proceeds if the build step succeeds.
📝 Committable suggestion