diff --git a/src/fsharp/fsi/FSIstrings.txt b/src/fsharp/fsi/FSIstrings.txt index d02cfeb79c499849fcd27fb801e058b480825ec2..c151f7b30e255745e873107847d24dde9db04dde 100644 --- a/src/fsharp/fsi/FSIstrings.txt +++ b/src/fsharp/fsi/FSIstrings.txt @@ -52,3 +52,5 @@ fsiBindingSessionTo,"Binding session to '%s'..." fsiProductName,"Microsoft (R) F# Interactive version %s" fsiProductNameCommunity,"F# Interactive for F# %s" shadowCopyReferences,"Prevents references from being locked by the F# Interactive process" +fsiOperationCouldNotBeCompleted,"Operation could not be completed due to earlier error" +fsiOperationFailed,"Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing" diff --git a/src/fsharp/fsi/fsi.fs b/src/fsharp/fsi/fsi.fs index cf9f02286ced460c410626b66d8a6026e6439ec2..6a90958b6a169090e59b124ea22e866c0af4c0c1 100644 --- a/src/fsharp/fsi/fsi.fs +++ b/src/fsharp/fsi/fsi.fs @@ -2280,6 +2280,11 @@ let internal DriveFsiEventLoop (fsi: FsiEvaluationSessionHostConfig, fsiConsoleO runLoop(); +/// Thrown when there was an error compiling the given code in FSI. +type FsiCompilationException(message: string, errorInfos: FSharpErrorInfo[] option) = + inherit System.Exception(message) + member __.ErrorInfos = errorInfos + /// The primary type, representing a full F# Interactive session, reading from the given /// text input, writing to the given text output and error writers. type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], inReader:TextReader, outWriter:TextWriter, errorWriter: TextWriter, fsiCollectible: bool, legacyReferenceResolver: ReferenceResolver.Resolver option) = @@ -2443,21 +2448,22 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i let fsiInteractionProcessor = FsiInteractionProcessor(fsi, tcConfigB, fsiOptions, fsiDynamicCompiler, fsiConsolePrompt, fsiConsoleOutput, fsiInterruptController, fsiStdinLexerProvider, lexResourceManager, initialInteractiveState) let commitResult res = - match res with + match res with | Choice1Of2 r -> r - | Choice2Of2 None -> failwith "Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing" + | Choice2Of2 None -> raise (FsiCompilationException(FSIstrings.SR.fsiOperationFailed(), None)) | Choice2Of2 (Some userExn) -> raise userExn - let commitResultNonThrowing errorOptions scriptFile (errorLogger: CompilationErrorLogger) res = + let commitResultNonThrowing errorOptions scriptFile (errorLogger: CompilationErrorLogger) res = let errs = errorLogger.GetErrors() - let userRes = - match res with + let errorInfos = ErrorHelpers.CreateErrorInfos (errorOptions, true, scriptFile, errs, true) + let userRes = + match res with | Choice1Of2 r -> Choice1Of2 r - | Choice2Of2 None -> Choice2Of2 (System.Exception "Operation could not be completed due to earlier error") + | Choice2Of2 None -> Choice2Of2 (FsiCompilationException(FSIstrings.SR.fsiOperationCouldNotBeCompleted(), Some errorInfos) :> exn) | Choice2Of2 (Some userExn) -> Choice2Of2 userExn // 'true' is passed for "suggestNames" because we want the FSI session to suggest names for misspellings and it won't affect IDE perf much - userRes, ErrorHelpers.CreateErrorInfos (errorOptions, true, scriptFile, errs, true) + userRes, errorInfos let dummyScriptFileName = "input.fsx" diff --git a/src/fsharp/fsi/fsi.fsi b/src/fsharp/fsi/fsi.fsi index 2897e36484d5329fb45b5034de04f583408e090f..8809c213a359bbf72681462e178079e470bf85ae 100644 --- a/src/fsharp/fsi/fsi.fsi +++ b/src/fsharp/fsi/fsi.fsi @@ -106,6 +106,12 @@ type public FsiEvaluationSessionHostConfig = /// Implicitly reference FSharp.Compiler.Interactive.Settings.dll abstract UseFsiAuxLib : bool +/// Thrown when there was an error compiling the given code in FSI. +[] +type FsiCompilationException = + inherit System.Exception + new : string * FSharpErrorInfo[] option -> FsiCompilationException + member ErrorInfos : FSharpErrorInfo[] option /// Represents an F# Interactive evaluation session. [] @@ -184,7 +190,7 @@ type FsiEvaluationSession = /// /// Due to a current limitation, it is not fully thread-safe to run this operation concurrently with evaluation triggered /// by input from 'stdin'. - member EvalExpressionNonThrowing : code: string -> Choice * FSharpErrorInfo[] + member EvalExpressionNonThrowing : code: string -> Choice * FSharpErrorInfo[] /// Format a value to a string using the current PrintDepth, PrintLength etc settings provided by the active fsi configuration object member FormatValue : reflectionValue: obj * reflectionType: System.Type -> string diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.cs.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.cs.xlf index c43178fe80a98ea0cabc5e01c9702f919e7cff63..453d98e749f5cb62307a45a7b2d8546d8837b8f3 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.cs.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.cs.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n Zastavilo se kvůli chybě.\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.de.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.de.xlf index 0e7145c703e26f148e179bf5cb680d33f3310301..9d11e8cf7008f6d2d043c6fb4ff8e4c837df540d 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.de.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.de.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n Aufgrund eines Fehlers beendet\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.es.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.es.xlf index 0ba7ef163b9173fdd1aa1bf3d078924717ac15dd..de2f164e3a8a5669078599d877246e9a4cfe015b 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.es.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.es.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n Detenido debido a un error.\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.fr.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.fr.xlf index 57ed7d784eda317b1f2747b181165c9236c9b594..040a8021fc7e664a7313bbcbeb0a284d1f5e4dcf 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.fr.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.fr.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n Arrêt en raison d'une erreur\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.it.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.it.xlf index d7f05d6aa9614f4d14017312be730e7aacd40ec9..9468b8aa2ae16ef9bb404d2e4b5185dda35f9562 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.it.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.it.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n Interruzione a causa di un errore\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.ja.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.ja.xlf index c70b2e1dd3c2aabbc0d2e2146a2654270f00fb23..81ab0861dc05ba6d24fed473e6a15a58b5c29e1d 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.ja.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.ja.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n エラーのため停止しました\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.ko.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.ko.xlf index b6af609a2a2e1c5550282136fd0301e0599e478b..f476d85f8eb977301c9f05588ba5bca2a5d726b5 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.ko.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.ko.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n 오류 때문에 중지되었습니다.\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.pl.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.pl.xlf index 82960cad8fd8e20b55b516afdd1696b0b0d1398e..24115c1fa37df2fddc8c362d76b6bdd7a22010eb 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.pl.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.pl.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n Zatrzymano ze względu na błąd\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.pt-BR.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.pt-BR.xlf index 41c3148c35619021c6d17ef7d002de926cd41297..ceaea230adac592fed27e38fd45984d421ecb0fc 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.pt-BR.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.pt-BR.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n Interrompido devido a erro\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.ru.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.ru.xlf index 0de5c8a527775317f2bde59679236a65d7f0d03a..25c322aa907aefb3f8e25908e6c2297d354ce7a2 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.ru.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.ru.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n Остановлено из-за ошибки\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.tr.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.tr.xlf index 61fb0cee68d4ab9d797452a5f54c97c2b3983a94..b061a19e37f8413ab6a9780e693ceb558da1df9c 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.tr.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.tr.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n Hata nedeniyle durduruldu\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.zh-Hans.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.zh-Hans.xlf index 4a8085973e77485b1c5a7e0bd8d991287188102e..6f28ddc77dd2556a5ba9bba754567af72d706191 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.zh-Hans.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.zh-Hans.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n 已因出错而停止\n diff --git a/src/fsharp/fsi/xlf/FSIstrings.txt.zh-Hant.xlf b/src/fsharp/fsi/xlf/FSIstrings.txt.zh-Hant.xlf index 4ba5fc71b7141d6f7f351f99be89ab0e01084f83..a8d771d1c37831ee34ee31bc82faa079553d6631 100644 --- a/src/fsharp/fsi/xlf/FSIstrings.txt.zh-Hant.xlf +++ b/src/fsharp/fsi/xlf/FSIstrings.txt.zh-Hant.xlf @@ -2,6 +2,16 @@ + + Operation could not be completed due to earlier error + Operation could not be completed due to earlier error + + + + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpErrorInfo use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing + + Stopped due to error\n 已因錯誤而停止\n diff --git a/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs b/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs index 82c9c1f329f3eeb728529fc9bd668d47257fa8cc..7452ab5bb72994db55d317afa87fe6f1deddd443 100644 --- a/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs +++ b/tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs @@ -90,3 +90,20 @@ type InteractiveTests() = let _result, errors = script.Eval(sprintf "#r \"%s\"" testAssembly) Assert.AreEqual(1, errors.Length) Assert.False(foundAssemblyReference) + + [] + member _.``Compilation errors report a specific exception``() = + use script = new FSharpScript() + let result, _errors = script.Eval("abc") + match result with + | Ok(_) -> Assert.Fail("expected a failure") + | Error(ex) -> Assert.IsInstanceOf(ex) + + [] + member _.``Runtime exceptions are propagated``() = + use script = new FSharpScript() + let result, errors = script.Eval("System.IO.File.ReadAllText(\"not-a-file-path-that-can-be-found-on-disk.txt\")") + Assert.IsEmpty(errors) + match result with + | Ok(_) -> Assert.Fail("expected a failure") + | Error(ex) -> Assert.IsInstanceOf(ex)