diff --git a/lib/master.pike.in b/lib/master.pike.in
index 797c8cca54a52bc1eee9c6301056e12ff3f50a92..b0a0258d83b7af189dc98590c895af04caf657d8 100644
--- a/lib/master.pike.in
+++ b/lib/master.pike.in
@@ -2114,6 +2114,19 @@ program cast_to_program(string pname,
 }
 
 
+protected string narrowify_string(string s)
+{
+  if (Builtin.string_width(s) <= 8) return s;
+  // Perform Unicode escaping.
+  return map(s/"",
+	     lambda(string s) {
+	       if (Builtin.string_width(s) <= 8) return s;
+	       int c = s[0] & 0xffffffff;
+	       if (c <= 0xffff) return sprintf("\\u%04x", c);
+	       return sprintf("\\U%08x", c);
+	     }) * "";
+}
+
 //! This function is called when an error occurs that is not caught
 //! with catch().
 void handle_error(array|object trace)
@@ -2134,14 +2147,14 @@ void handle_error(array|object trace)
 	if (catch {
 	  string msg = [string]x[0];
 	  array bt = [array]x[1];
-	  werror("%s", msg);
-	  werror("%O\n", bt);
+	  werror("%s", narrowify_string(msg));
+	  werror(narrowify_string(sprintf("%O\n", bt)));
 	}) {
-	  werror("%O\n", x);
+	  werror(narrowify_string(sprintf("%O\n", x)));
 	}
       };
-      werror("Original error:\n"
-	     "%O\n", trace);
+      werror(narrowify_string(sprintf("Original error:\n"
+				      "%O\n", trace)));
     }) {
       werror("sprintf() failed to write error.\n");
     }
@@ -4152,7 +4165,7 @@ void compile_error(string file,int line,string err)
   if(! (val = get_inhibit_compile_errors() ))
   {
     werror( "%s:%s:%s\n",trim_file_name(file),
-	    line?(string)line:"-",err );
+	    line?(string)line:"-",narrowify_string(err) );
   }
   else if(objectp(val) ||
 	  programp(val) ||
@@ -4182,7 +4195,7 @@ void compile_warning(string file,int line,string err)
   {
     if(want_warnings)
       werror( "%s:%s: Warning: %s\n",trim_file_name(file),
-	      line?(string)line:"-",err );
+	      line?(string)line:"-",narrowify_string(err) );
   }
   else if (objectp(val) && val->compile_warning) {
     ([function(string,int,string:void)]([object]val)
@@ -4389,6 +4402,9 @@ class Describer
       }
       break;
     }
+    // Objects may have _sprintfs that output wide characters,
+    // and function names may be wide, etc...
+    res = narrowify_string(res);
     if (stringp(ident[m]))
       return ident[m] + "=" + res;
     return res;
@@ -5091,7 +5107,7 @@ array get_backtrace (object|array err)
   mixed _v__ = (val);							\
   werror ("  returned %s\n",						\
 	  zero_type (_v__) ? "UNDEFINED" :				\
-	  sprintf ("%O", _v__));					\
+	  narrowify_string(sprintf ("%O", _v__)));			\
   return _v__;								\
 } while (0)
 #else
@@ -5105,7 +5121,7 @@ array get_backtrace (object|array err)
   mixed _v__ = (val);							\
   werror ("  returned %s\n",						\
 	  zero_type (_v__) ? "UNDEFINED" :				\
-	  sprintf ("%O", _v__));					\
+	  narrowify_string(sprintf ("%O", _v__)));			\
   return _v__;								\
 } while (0)
 #else
diff --git a/lib/modules/Tools.pmod/Hilfe.pmod b/lib/modules/Tools.pmod/Hilfe.pmod
index e6debfeb0d6b7a264fd2ba10e9c11c59bd09b094..0c5a9f707afad205b03320ff361b783d96b7d445 100644
--- a/lib/modules/Tools.pmod/Hilfe.pmod
+++ b/lib/modules/Tools.pmod/Hilfe.pmod
@@ -1496,6 +1496,17 @@ class Evaluator {
       if(arrayp(in)) in *= "";
       if(sizeof(args))
 	in = sprintf(in, @args);
+      if (String.width(in) > 8) {
+	// Variable and function names may contain wide characters...
+	// Perform Unicode escaping.
+	in = map(in/"",
+		 lambda(string s) {
+		   if (String.width(s) <= 8) return s;
+		   int c = s[0] & 0xffffffff;
+		   if (c <= 0xffff) return sprintf("\\u%04x", c);
+		   return sprintf("\\U%08x", c);
+		 }) * "";
+      }
       int ret = write(in);
       if(!ret && sizeof(in)) return sizeof(in);
       return ret;