-
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 |
node <- coreLift findNode | ||
quoted_node <- pure $ "\"" ++ node ++ "\"" -- Windows often have a space in the path. | ||
coreLift_ $ system (quoted_node ++ " " ++ outn) | ||
system $ "\"" ++ node ++ "\" " ++ out -- Windows often have a space in the path. |
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.
Why does escapeArg
not enclose in quotes in Windows?
Idris2/libs/base/System/Escape.idr
Lines 10 to 14 in ec74792
escapeArg : String -> String | |
escapeArg cmd = let escapedCmdChars = pack $ unpack cmd >>= escapeArgChar in | |
if isWindows | |
then escapedCmdChars | |
else "\"" ++ escapedCmdChars ++ "\"" |
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.
Oh, it escapes spaces, okay
Idris2/libs/base/System/Escape.idr
Line 21 in ec74792
c == ' ' || c == '\t' || c == '\n' || c == ';' || c == ',' || c == '=' || c == '\x0B' || c == '\x0C' || c == '\xFF' || |
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.
Maybe, it worth to add a comment nearby about this to make it clear for the future readers
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.
CI on windows fails if I replace quoting with escapeArg
. It's looks like problem with escapeArg
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.
CI on windows fails if I replace quoting with
escapeArg
. It's looks like problem withescapeArg
I think it's a Node.js problem nodejs/node#56146
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
).