-
Notifications
You must be signed in to change notification settings - Fork 380
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
[ refactor ] Improve error handling in Core
#3434
base: main
Are you sure you want to change the base?
Conversation
d89dd5a
to
49fd711
Compare
src/Compiler/Scheme/Gambit.idr
Outdated
ok <- coreLift $ system cmd | ||
if ok == 0 | ||
then pure (Just execPath) | ||
else pure Nothing | ||
safeSystem cmd | ||
pure (Just execPath) |
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.
This is not logically equivalent. Why is it legitimate to drop the Nothing
branch?
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.
safeSystem
throws an error if the exit code is not zero. This makes the errors more clear
src/Compiler/Scheme/Racket.idr
Outdated
when mkexec $ logTime 1 "Build racket" $ | ||
safeSystem $ raco ++ ["-o", outBinAbs, outRktAbs] | ||
-- TODO: add launcher script | ||
let outShRel = outputDir </> outfile | ||
makeShPlatform isWindows (if mkexec then "" else racket ++ " ") outShRel appDirRel outRktFile | ||
handleFileError outShRel $ chmodRaw outShRel 0o755 | ||
pure (Just outShRel) |
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.
Again we're also dropping the Nothing
branch
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.
safeSystem
throw NonZeroExitCode
. I replaced all Nothing
with throw
. Currently Nothing
just wraps around to CompilationFailed
. A more specific cause of the error is passed to throw
.
Lines 815 to 818 in ec74792
ok <- compile cg tm_erased outfile | |
maybe (pure CompilationFailed) | |
(pure . Compiled) | |
ok |
(tmpDir : String) -> ClosedTerm -> Core ExitCode | ||
executeExpr c s tmpDir tm = do | ||
out <- compileExpr False c s tmpDir tmpDir tm "_tmpchez" | ||
system $ escapeArg out |
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.
I think an explicit escapeArg
is clearer than a single element list
b3320e9
to
8c60a6e
Compare
This PR is ready for review. The lsp build is failing because I deleted |
If my refactoring is questionable, I can put everything related to #3427 in a separate PR to simplify the review |
…ir` and `changeDir`
8c60a6e
to
5135ae4
Compare
Description
Core
.NonZeroExitCode
,SystemError
,CodegenNotFound
,UnsupportedOpertaion
.coreLift_
calls replaced by explicit result processing.Maybe
fromcompileExpr
andincCompileFile
signatures. Instead of returningNothing
,throw
is used. Earlier both variants were found in the code. Usingthrow
allows you to pass a more clear error.--exec
#3427: the--exec
command returns the program exit code. If several--exec
options are passed, the result of the last execution will be returned.CompilationFailed
fromREPLResult
. More specific errors usingthrow
are returned instead.Should this change go in the CHANGELOG?
implementation, I have updated
CHANGELOG_NEXT.md
(and potentially alsoCONTRIBUTORS.md
).