From 56a299df79b88b7038a8a5f79f3c0c401f6d63d8 Mon Sep 17 00:00:00 2001 From: hallgren Date: Wed, 3 Apr 2013 06:42:08 +0000 Subject: [PATCH] Prevent Unicode characters in warning messages from stopping grammar compilation When compiling a grammar containing characters that are not supported in the current locale, warning messages could cause GF fail with hPutChar: invalid argument (Invalid or incomplete multibyte or wide character) With this quick fix, warning messages that can not be displayed are silently truncated instead, and compilation continues. --- src/compiler/GF/Compile.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/GF/Compile.hs b/src/compiler/GF/Compile.hs index 84aa3d7d9..91781d3ce 100644 --- a/src/compiler/GF/Compile.hs +++ b/src/compiler/GF/Compile.hs @@ -83,10 +83,12 @@ intermOut opts d doc warnOut opts warnings | null warnings = return () - | otherwise = ioeIO (hPutStrLn stderr $ - if flag optVerbosity opts == Normal - then ('\n':warnings) - else warnings) + | otherwise = ioeIO $ hPutStrLn stderr ws `catch` oops + where + oops _ = hPutStrLn stderr "" -- prevent crash on character encoding problem + ws = if flag optVerbosity opts == Normal + then '\n':warnings + else warnings -- | the environment type CompileEnv = (Int,SourceGrammar,ModEnv)