diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 2f5ff604df..e0837c6aa0 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -27,6 +27,10 @@ declare var module: any; declare var process: any; declare var global: any; +enum SystemError { + UnsupportedFileEncoding +} + var sys: System = (function () { function getWScriptSystem(): System { @@ -68,7 +72,9 @@ var sys: System = (function () { return fileStream.ReadText(); } catch (e) { - throw e.number === -2147024809 ? new Error(ts.Diagnostics.Unsupported_file_encoding.key) : e; + if (e.number === -2147024809) { + e.systemError = SystemError.UnsupportedFileEncoding; + } } finally { fileStream.Close(); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index c8cccd2da1..e6e48e32e4 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -71,6 +71,15 @@ module ts { return true; } + + function getSystemErrorMessage(e: SystemError): string { + switch (e) { + case SystemError.UnsupportedFileEncoding: + return getDiagnosticText(Diagnostics.Unsupported_file_encoding); + default: + Debug.assert("Unreachable code in 'getSystemErrorMessage'"); + } + } function countLines(program: Program): number { var count = 0; @@ -149,7 +158,7 @@ module ts { } catch (e) { if (onError) { - onError(e.message); + onError(e.systemError ? getSystemErrorMessage(e.systemError) : e.message); } text = ""; }