-
-
Notifications
You must be signed in to change notification settings - Fork 11
fix(core): handle io exceptions in subprocess #218
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 1 commit
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -81,6 +81,7 @@ handle config = do | |||||||||||||
|
|
||||||||||||||
| completion <- | ||||||||||||||
| Subprocess.openInherit "nix-build" (Array.fromLinkedList ["-E", buildExpression]) rootFolder Subprocess.InheritBOTH | ||||||||||||||
| |> Task.mapError (\_ -> CustomError "Failed to run nix-build") | ||||||||||||||
| if completion.exitCode != 0 | ||||||||||||||
| then errorOut completion.stderr | ||||||||||||||
| else print completion.stdout | ||||||||||||||
|
Comment on lines
85
to
87
Contributor
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 | 🔵 Trivial Remove the vestigial print statement. Mortal architect! When thou invokest Apply this refinement: if completion.exitCode != 0
then errorOut completion.stderr
- else print completion.stdout
+ else Task.yield ()Observe how 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ handle config = do | |||||||||||||
| let rootFolder = [path|.|] | ||||||||||||||
| completion <- | ||||||||||||||
| Subprocess.openInherit [fmt|./result/bin/#{projectName}|] (Array.fromLinkedList []) rootFolder Subprocess.InheritBOTH | ||||||||||||||
| |> Task.mapError (\_ -> CustomError "Failed to run the built application") | ||||||||||||||
| if completion.exitCode != 0 | ||||||||||||||
| then errorOut completion.stderr | ||||||||||||||
| else print completion.stdout | ||||||||||||||
|
Comment on lines
26
to
28
Contributor
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 | 🔵 Trivial Remove the phantom print statement. Behold the same transgression as in Apply this correction: if completion.exitCode != 0
then errorOut completion.stderr
- else print completion.stdout
+ else Task.yield ()Align with the wisdom demonstrated in 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,7 @@ handle config = do | |
|
|
||
| completion <- | ||
| Subprocess.openInherit "nix-shell" (Array.fromLinkedList ["-E", shellExpression]) rootFolder Subprocess.InheritBOTH | ||
| |> Task.mapError (\_ -> CustomError "Failed to open the shell") | ||
|
Contributor
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. Preserve the original error information for diagnostics. By the divine decree previously spoken! This lambda also discards the specific error details with Apply this correction: - |> Task.mapError (\_ -> CustomError "Failed to open the shell")
+ |> Task.mapError (\err -> CustomError [fmt|Failed to open the shell: #{err}|])Consider extracting a shared helper function to avoid this duplication across Build.hs, Run.hs, and Shell.hs: mapSubprocessError :: Text -> Subprocess.Error -> Error
mapSubprocessError context err = CustomError [fmt|#{context}: #{err}|]🤖 Prompt for AI Agents
Member
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. Agree
Contributor
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. 🧩 Analysis chain@NickSeagull By thy divine approval, I shall illuminate the path to righteous error handling! Let me first examine the current state of Build.hs and Run.hs to provide thee with complete guidance. 🏁 Script executed: Length of output: 722 🏁 Script executed: Length of output: 146 🏁 Script executed: Length of output: 0 🏁 Script executed: Length of output: 79 🏁 Script executed: Length of output: 79 @NickSeagull Behold! I have surveyed thy domain and shall now provide the complete implementation to preserve error diagnostics across all affected modules. Changes Required1. cli/src/Neo/Shell.hs (Line 84) completion <-
Subprocess.openInherit "nix-shell" (Array.fromLinkedList ["-E", shellExpression]) rootFolder Subprocess.InheritBOTH
|> Task.mapError (\err -> CustomError [fmt|Failed to open the shell: #{err}|])2. cli/src/Neo/Build.hs (around line where nix-build is called) completion <-
Subprocess.openInherit "nix-build" (Array.fromLinkedList ["-E", buildExpression, "--no-out-link"]) rootFolder Subprocess.InheritBOTH
|> Task.mapError (\err -> CustomError [fmt|Failed to run nix-build: #{err}|])3. cli/src/Neo/Run.hs (around line where the built application runs) completion <-
Subprocess.openInherit exeName arguments rootFolder Subprocess.InheritBOTH
|> Task.mapError (\err -> CustomError [fmt|Failed to run the built application: #{err}|])RationaleBy thy divine wisdom, I have chosen the inline approach rather than extracting a shared helper because:
The ( o.o ) Verily! The divine order of error If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
||
| if completion.exitCode != 0 | ||
| then errorOut completion.stderr | ||
| else Task.yield () | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ module Subprocess ( | |
| import Array (Array) | ||
| import Array qualified | ||
| import Basics | ||
| import GHC.IO.Exception qualified as Exception | ||
| import Maybe qualified | ||
| import Path (Path) | ||
| import Path qualified | ||
|
|
@@ -45,7 +46,12 @@ data InheritStream | |
| deriving (Eq, Ord, Show) | ||
|
|
||
|
|
||
| openInherit :: Text -> Array Text -> Path -> InheritStream -> Task _ Completion | ||
| data Error | ||
| = NotExecutable | ||
| deriving (Show) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
| openInherit :: Text -> Array Text -> Path -> InheritStream -> Task Error Completion | ||
| openInherit executable arguments directory inheritStream = do | ||
| let (stdoutStream, stderrStream) = case inheritStream of | ||
| InheritSTDOUT -> (System.Process.Inherit, System.Process.CreatePipe) | ||
|
|
@@ -69,8 +75,12 @@ openInherit executable arguments directory inheritStream = do | |
| (_, _, _, ph) <- | ||
| -- System.Process.readCreateProcessWithExitCode processToExecute "" | ||
| System.Process.createProcess processToExecute | ||
| |> Task.fromIO | ||
| ec <- System.Process.waitForProcess ph |> Task.fromIO | ||
| |> Task.fromFailableIO @Exception.IOError | ||
| |> Task.mapError (\_ -> NotExecutable) | ||
|
Member
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. Can you map to the other types of errors described in the other comment? |
||
| ec <- | ||
| System.Process.waitForProcess ph | ||
| |> Task.fromFailableIO @Exception.IOError | ||
| |> Task.mapError (\_ -> NotExecutable) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| let exitCode = case ec of | ||
| System.Exit.ExitSuccess -> 0 | ||
| System.Exit.ExitFailure code -> code | ||
|
|
@@ -79,6 +89,6 @@ openInherit executable arguments directory inheritStream = do | |
| Task.yield Completion {exitCode, stdout, stderr} | ||
|
|
||
|
|
||
| open :: Text -> Array Text -> Path -> Task _ Completion | ||
| open :: Text -> Array Text -> Path -> Task Error Completion | ||
| open executable arguments directory = | ||
| openInherit executable arguments directory InheritNONE | ||
Uh oh!
There was an error while loading. Please reload this page.