diff --git a/src/fsharp/CompileOptions.fs b/src/fsharp/CompileOptions.fs
index 3a3ecf332f4..1e2fe37a9f7 100644
--- a/src/fsharp/CompileOptions.fs
+++ b/src/fsharp/CompileOptions.fs
@@ -256,12 +256,20 @@ let ParseCompilerOptions (collectOtherArgument : string -> unit, blocks: Compile
| [] -> ()
| ((rsp: string) :: t) when rsp.StartsWith("@") ->
let responseFileOptions =
- let path = rsp.TrimStart('@') |> FileSystem.GetFullPathShim
-
- if not (FileSystem.SafeExists path) then
+ let fullpath =
+ try
+ Some (rsp.TrimStart('@') |> FileSystem.GetFullPathShim)
+ with _ ->
+ None
+
+ match fullpath with
+ | None ->
+ errorR(Error(FSComp.SR.optsResponseFileNameInvalid(rsp),rangeCmdArgs))
+ []
+ | Some(path) when not (FileSystem.SafeExists path) ->
errorR(Error(FSComp.SR.optsResponseFileNotFound(rsp, path),rangeCmdArgs))
[]
- else
+ | Some path ->
match ResponseFile.parseFile path with
| Choice2Of2 _ ->
errorR(Error(FSComp.SR.optsInvalidResponseFile(rsp, path),rangeCmdArgs))
diff --git a/src/fsharp/FSComp.txt b/src/fsharp/FSComp.txt
index fd879611611..ee15b73cba1 100644
--- a/src/fsharp/FSComp.txt
+++ b/src/fsharp/FSComp.txt
@@ -1266,3 +1266,4 @@ estApplyStaticArgumentsForMethodNotImplemented,"A type provider implemented GetS
3190,checkLowercaseLiteralBindingInPattern,"Lowercase literal '%s' is being shadowed by a new pattern with the same name. Only uppercase and module-prefixed literals can be used as named patterns."
3191,optsInvalidResponseFile,"Invalid response file '%s' ( '%s' )"
3192,optsResponseFileNotFound,"Response file '%s' not found in '%s'"
+3193,optsResponseFileNameInvalid,"Response file name '%s' is empty, contains invalid characters, has a drive specification without an absolute path, or is too long"
diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/E_responsefile_not_found.fs b/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/E_responsefile_not_found.fs
index 94872625c24..e566097a42c 100644
--- a/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/E_responsefile_not_found.fs
+++ b/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/E_responsefile_not_found.fs
@@ -1,3 +1,3 @@
// #NoMT #CompilerOptions
//
-exit 0
+exit 1
diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/E_responsefile_path_invalid.fs b/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/E_responsefile_path_invalid.fs
new file mode 100644
index 00000000000..860167f29de
--- /dev/null
+++ b/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/E_responsefile_path_invalid.fs
@@ -0,0 +1,3 @@
+// #NoMT #CompilerOptions
+//
+exit 1
diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/env.lst b/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/env.lst
index b9290d94807..45f9472bb80 100644
--- a/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/env.lst
+++ b/tests/fsharpqa/Source/CompilerOptions/fsc/responsefile/env.lst
@@ -5,3 +5,4 @@
SOURCE="responsefile01.fs \@empty_rs.rsp \@rs2.rsp \@empty_rs.rsp " # responsefile01.fs nested response file
SOURCE="responsefile02.fs" SCFLAGS="\@rs1_multiline_and_comments.rsp" # responsefile02.fs response file multiline
SOURCE="E_responsefile_not_found.fs" COMPILE_ONLY=1 SCFLAGS="\@not_exists" # E_responsefile_not_found.fs error if response file does not exists
+ SOURCE="E_responsefile_path_invalid.fs" COMPILE_ONLY=1 SCFLAGS="\@" # E_responsefile_path_invalid.fs error if response file name is empty or invalid