IncompatibleEncodingError

e$B?\F#$G$9!#e(B

Ruby 1.9e$B$G$O$?$/$5$s$Ne(B"incompatible encodings: …“e$B$H$$$&Nce(B
e$B30$rL$K$9$k$H;W$&$N$G$9$,!”$=$NNc30%/%i%9$re(BArgumentErrore$B$+e(B
e$B$ie(BIncompatibleEncodingErrore$B$H$$$&$h$&$J@lMQ$NNc30%/%i%9$K$9e(B
e$B$k$H$$$&$N$O$I$&$G$7$g$&$+!)e(B

“incompatible encodings: …“e$B$J%(%i!<$rNc30$rJa$^$($d$9$/$9e(B
e$B$k$H!”%(%s%3!<%G%#%s%0$r@_Dj$7D>$7$F:F%A%c%l%s%8$9$k$H$+!”?Fe(B
e$B@Z$J%(%i!<%a%C%;!<%8$r=PNO$9$k$H$$$&$h$&$J$3$H$,$7$d$9$/$J$ke(B
e$B$H;W$$$^$9!#e(B

def parse(input)
begin
MyParser.new(input).parse
rescue IncompatibleEncodingError
puts “input encoding must be #{$!.expected_encoding}”
puts “but was #{$!.actual_encoding}”
nil
end
end

e$B@.@%$G$9!#e(B

Kouhei S. wrote:

def parse(input)
begin
MyParser.new(input).parse
rescue IncompatibleEncodingError
puts “input encoding must be #{$!.expected_encoding}”
puts “but was #{$!.actual_encoding}”
nil
end
end

e$B$?$7$+$K$=$l$O$$$$$+$b$7$l$^$;$s!#e(B

e$BLB$&$H$3$m$,!"e(B

  • IncompatibleEncodingError e$B$K$9$k$+!"e(BEncodingError
    e$B$H0lCJ9-$/<h$C$F$*$/$+e(B
  • e$B%9!<%Q!<%/%i%9$re(B ArgumentError e$B$K$9$k$+e(B
    e$B$"$?$j$G$7$g$&$+!#e(B

e$B$J$*!"8=:_e(B incompatible encoding e$B$de(B differ e$B$Ne(B
ArgumentError e$B$,Ej$2$i$l$k>l9g!"e(B
e$B4|BT$5$l$k%(%s%3!<%G%#%s%0$,$J$$>l9g$bB?$$$N$G$O$J$$$+$H;W$$$^$9!#e(B

e$B4pK\E*$K$Oe(B receiver e$B$N%(%s%3!<%G%#%s%0$He(B argument
e$B$N%(%s%3!<%G%#%s%0$,e(B
e$B0[$J$k$H$+$G$7$g$&$M!#e(B

e$B$D$^$j!"e(Breceriver e$B$He(B argumente$B$,$H$l$k$Y$-$+$J$!!#e(B

e$B?\F#$G$9!#e(B

In [email protected]
“[ruby-dev:35201] Re: IncompatibleEncodingError” on Sun, 22 Jun 2008
16:41:16 +0900,
“NARUSE, Yui” [email protected] wrote:

Ruby 1.9e$B$G$O$?$/$5$s$Ne(B"incompatible encodings: …“e$B$H$$$&Nce(B
e$B30$rL$K$9$k$H;W$&$N$G$9$,!”$=$NNc30%/%i%9$re(BArgumentErrore$B$+e(B
e$B$ie(BIncompatibleEncodingErrore$B$H$$$&$h$&$J@lMQ$NNc30%/%i%9$K$9e(B
e$B$k$H$$$&$N$O$I$&$G$7$g$&$+!)e(B

e$BLB$&$H$3$m$,!"e(B

  • IncompatibleEncodingError e$B$K$9$k$+!"e(BEncodingError e$B$H0lCJ9-$/<h$C$F$*$/$+e(B
  • e$B%9!<%Q!<%/%i%9$re(B ArgumentError e$B$K$9$k$+e(B
    e$B$"$?$j$G$7$g$&$+!#e(B

EncodingErrore$B$N2<$Ke(BIncompatibleEncodingErrore$B$,$h$$$H;W$$$^$9!#e(B
e$B$H$$$&$N$b!"e(B

e$B$J$*!"8=:_e(B incompatible encoding e$B$de(B differ e$B$Ne(B ArgumentError e$B$,Ej$2$i$l$k>l9g!"e(B
e$B4|BT$5$l$k%(%s%3!<%G%#%s%0$,$J$$>l9g$bB?$$$N$G$O$J$$$+$H;W$$$^$9!#e(B

e$B$H$$$&;~$O!“e(BIncompatibleEncodingErrore$B$8$c$J$$$b$C$H$=$l$C$]e(B
e$B$$Nc30$,$-$?J}$,4r$7$=$&$@$+$i$G$9!#$=$7$F!”%(%s%3!<%G%#%s%0e(B
e$B4X78$NNc30$r$^$H$a$FJa$^$($?$$$H$-$N$?$a$Ke(BEncodingErrore$B$,?Fe(B
e$B$K$J$C$F$$$k$HJXMx$=$&$@$+$i$G$9!#e(B

e$B%9!<%Q!<%/%i%9$Oe(BArgumentErrore$B$8$c$J$/$F$b$h$$5$$,$7$^$9!#e(B
e$B!J8_49@-$r5$$K$7$J$$$J$i!Ke(B

e$BNc$($P!"$3$&$$$&$H$-$Oe(BArgumentErrore$B$O$J$s$+0c$&$h$&$J5$$,$9e(B
e$B$k$+$i$G$9!#e(B

coding: utf-8

“e$B$”$*$$$($*e(B".sub(/e$B$$e(B/) {“e$B$+e(B”.encode(“eucJP”)}

e$B@.@%$G$9!#e(B

Kouhei S. wrote:

EncodingErrore$B$N2<$Ke(BIncompatibleEncodingErrore$B$,$h$$$H;W$$$^$9!#e(B
e$B$H$$$&$N$b!"e(B

e$B$J$*!"8=:_e(B incompatible encoding e$B$de(B differ e$B$Ne(B ArgumentError e$B$,Ej$2$i$l$k>l9g!"e(B
e$B4|BT$5$l$k%(%s%3!<%G%#%s%0$,$J$$>l9g$bB?$$$N$G$O$J$$$+$H;W$$$^$9!#e(B

e$B$H$$$&;~$O!“e(BIncompatibleEncodingErrore$B$8$c$J$$$b$C$H$=$l$C$]e(B
e$B$$Nc30$,$-$?J}$,4r$7$=$&$@$+$i$G$9!#$=$7$F!”%(%s%3!<%G%#%s%0e(B
e$B4X78$NNc30$r$^$H$a$FJa$^$($?$$$H$-$N$?$a$Ke(BEncodingErrore$B$,?Fe(B
e$B$K$J$C$F$$$k$HJXMx$=$&$@$+$i$G$9!#e(B

IRC e$B$G$bOC$7$?7k2L!"e(B

Encoding::IncompatibleError < StandardError

e$B$r?7@_$H$$$&$N$,:#$N$H$3$m:G1&Mc$K$J$C$F$$$^$9!#e(B
Encoding e$B$H$+e(B Error e$B$H$+2?EY$b=q$+$J$/$F$$$$$7!#e(B

e$B$3$s$J46$8$G$I$&$G$7$g$&!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:35210] Re: IncompatibleEncodingError”
on Tue, 24 Jun 2008 01:31:50 +0900, “NARUSE, Yui”
[email protected] writes:

|Encoding::IncompatibleError < StandardError
|
|e$B$r?7@_$H$$$&$N$,:#$N$H$3$m:G1&Mc$K$J$C$F$$$^$9!#e(B
|Encoding e$B$H$+e(B Error e$B$H$+2?EY$b=q$+$J$/$F$$$$$7!#e(B
|
|e$B$3$s$J46$8$G$I$&$G$7$g$&!#e(B

e$B$&!<$s!“$^$”!"$$$$$s$8$c$J$$$G$7$g$&$+!#e(B

At Tue, 24 Jun 2008 01:38:47 +0900,
matz wrote:

うーん、まあ、いいんじゃないでしょうか。
 ほかに Encoding é–¢ä¿‚ã®ã‚¨ãƒ©ãƒ¼ã‚’è¿½åŠ ã™ã‚‹ã¨ãã‚‚ StandardError の
直下にぶらさげるんでしょうか。

 IncompatibleEncodingError ってのは Encoding 関係で複数の例外を
区別する必要が生じてからでよいので、とりあえず

class EncodingError < StandardError; end

だけ導入するのはどうでしょうか。

At 21:07 08/06/24, Akinori MUSHA wrote:

At Tue, 24 Jun 2008 01:38:47 +0900,
matz wrote:

In message “Re: [ruby-dev:35210] Re: IncompatibleEncodingError”
on Tue, 24 Jun 2008 01:31:50 +0900, “NARUSE, Yui” [email protected]
writes:

|Encoding::IncompatibleError < StandardError

e$B!!$[$+$Ke(B Encoding e$B4X78$N%(%i!<$rDI2C$9$k$H$-$be(B StandardError e$B$Ne(B
e$BD>2<$K$V$i$5$2$k$s$G$7$g$&$+!#e(B

e$B!!e(BIncompatibleEncodingError e$B$C$F$N$Oe(B Encoding e$B4X78$GJ#?t$NNc30$re(B
e$B6hJL$9$kI,MW$,@8$8$F$+$i$G$h$$$N$G!“$H$j$”$($:e(B

class EncodingError < StandardError; end

e$B$@$1F3F~$9$k$N$O$I$&$G$7$g$&$+!#e(B

Encoding e$B$He(B transcode e$B$r0l=o$K$7$?J}$,$$$$$H9M$($k$H!"e(B
e$B8=:_0lHLE*$JNc30$K$J$C$F$$$ke(B transcode.c e$BFb$N0lIt$N$H$3$m$be(B
Encoding:: e$B2<$KF~$l$k$3$H$,9M$($i$l$k!#e(B

e$B8=:_$Ne(B transcode.c e$BFb$Ne(B rb_raise
e$B$rJ,@O$7$^$9$H<!$NDL$j$K$J$j$^$9e(B:

    rb_raise(rb_eArgError, "transcoder from %s to %s has been 

already registered",
e$BFbIt%(%i!<$_$?$$$J$b$N$G!"<oN`$O$=$l$[$I5$$K$7$J$/$F$$$$!#e(B

    rb_raise(rb_eArgError, "invalid library name - %s",

e$BFbIt%(%i!<$_$?$$$J$b$N$G!"<oN`$O$=$l$[$I5$$K$7$J$/$F$$$$!#e(B

    rb_raise(rb_eRuntimeError /*@@@change exception*/, "conversion 

undefined for byte sequence (maybe invalid byte sequence)“);
e$BJQ49$,L$Dj5A$G!”$3$3$Oe(B Encoding::UndefinedCharacterError
e$B$H$+=P$O$I$&$G$7$g$&$+!#e(B
e$BE57?Nc$Oe(B UTF-8 e$B$+$iNc$($Pe(B EUC-JP e$B$X$NJQ49$G!"e(BEUC-JP
e$B$GI=8=$G$-$J$$J8;z$N>l9g!#e(B

    rb_raise(rb_eArgError, "unknown value for invalid: setting");

e$B85$N%G!<%?$KLdBj$,$“$k$H$$$&$3$H$G!”$3$l$OB>$N$H$3$m$GF1$8%(%i!<$,=P$k$He(B
e$B0l=o$K$7$?$$$H;W$$$^$9!#E57?Nc$Oe(B UTF-8 e$B$Ge(B UTF-8
e$B=P$J$$%P%$%HNs$J$I!#e(B

    rb_raise(rb_eArgError, "wrong number of arguments (%d for 

1…2)", argc);
e$B$3$l$Oe(B encode e$B%a%>%I$KEj$2$?0z?t$N?t$,0c$&$H$$$&$3$H$G!"B?J,e(B
ArgError e$B$G$$$$$@$m$&!#e(B

    rb_raise(rb_eArgError, "transcoding not supported (from %s to 

%s)“, from_e, to_e);
e$B$3$l$O3d$j$He(B rescue e$B$9$k$N$,B?$$$N$G$O$J$$$+$H;W$$$^$9e(B
(e$BNc$($P2?$+FC<l$Je(B encoding
e$B$XJQ49$7$F$$F!"$3$l$,$@$a$G$7$?$iF1$87ONs$N$b$C$H%Y!<%8%C%/$J$b$N$r$d$C$F$$k$H$+e(B)
e$B$J$N$G!”$b$7$+$7$F6hJL$7$F$b$$$$$N$+$J!#e(B

    rb_raise(rb_eArgError, "not fully converted, %td bytes left", 

sp+slen-fromp);
e$B$3$l$OJ8;z$,ESCf$G@Z$i$l$F$$$k>l9g$J$I5/$3$j$^$9$N$G!"e(BEncoding::
e$B2<$G$$$$$H;W$$$^$9!#e(B

e$B%"%I%P%$%9$r59$7$/$*4j$$$7$^$9!#e(B Martin.

#-#-# Martin J. Du"rst, Assoc. Professor, Aoyama Gakuin University
#-#-# http://www.sw.it.aoyama.ac.jp mailto:[email protected]

At Wed, 25 Jun 2008 10:48:06 +0900,
e$B@.@%$G$9!#e(B

Martin D. wrote:

e$B!!$[$+$Ke(B Encoding e$B4X78$N%(%i!<$rDI2C$9$k$H$-$be(B StandardError e$B$Ne(B
e$B8=:_0lHLE*$JNc30$K$J$C$F$$$ke(B transcode.c e$BFb$N0lIt$N$H$3$m$be(B
Encoding:: e$B2<$KF~$l$k$3$H$,9M$($i$l$k!#e(B

Transcodee$B%/%i%9$,:n$i$l$k$3$H$,$J$$$J$i$P!“0l=o$NJ}$,$$$$$+$b$7$l$^$;$s!#e(B
e$B:n$i$l$k$3$H$,$b$7$”$k$H!"G:$^$7$$$G$9$M$’!#e(B

e$B8=:_$Ne(B transcode.c e$BFb$Ne(B rb_raise e$B$rJ,@O$7$^$9$H<!$NDL$j$K$J$j$^$9e(B:

    rb_raise(rb_eArgError, "transcoder from %s to %s has been already registered",

e$BFbIt%(%i!<$_$?$$$J$b$N$G!"<oN`$O$=$l$[$I5$$K$7$J$/$F$$$$!#e(B

    rb_raise(rb_eArgError, "invalid library name - %s",

e$BFbIt%(%i!<$_$?$$$J$b$N$G!"<oN`$O$=$l$[$I5$$K$7$J$/$F$$$$!#e(B

e$BF10U$7$^$9!#e(B
e$B$`$7$m$3$l$i$Oe(B rb_bug e$B$H$+$NJ}$,$$$$$N$+$b!#e(B

    rb_raise(rb_eRuntimeError /*@@@change exception*/, "conversion undefined for byte sequence (maybe invalid byte sequence)");

e$BJQ49$,L$Dj5A$G!"$3$3$Oe(B Encoding::UndefinedCharacterError e$B$H$+=P$O$I$&$G$7$g$&$+!#e(B
e$BE57?Nc$Oe(B UTF-8 e$B$+$iNc$($Pe(B EUC-JP e$B$X$NJQ49$G!"e(BEUC-JP e$B$GI=8=$G$-$J$$J8;z$N>l9g!#e(B

UndefinedCharacterError e$B$G$7$g$&$Me(B
e$B%(%i!<%a%C%;!<%8$Oe(B
"conversion undefined in for byte sequence in "
e$B$H$$$&$h$&$K!"e(Bfrom encoding e$B$He(B to encoding
e$B$,J,$+$C$?J}$,$$$$$+$b$7$l$^$;$s!#e(B

    rb_raise(rb_eArgError, "unknown value for invalid: setting");

e$B85$N%G!<%?$KLdBj$,$"$k$H$$$&$3$H$G!"$3$l$OB>$N$H$3$m$GF1$8%(%i!<$,=P$k$He(B
e$B0l=o$K$7$?$$$H;W$$$^$9!#E57?Nc$Oe(B UTF-8 e$B$Ge(B UTF-8 e$B=P$J$$%P%$%HNs$J$I!#e(B

e$B$3$N%(%i!<$C$F!"e(BString#encode(enc, invalid: value) e$B$Ne(B value
e$B$,IT@5$J>l9g$Ne(B
e$B%(%i!<$8$c$J$$$G$9$+$M!#e(B

e$B$5$F$*$-!"2<$N%G!<%?$KLdBj$,$k>l9g$Oe(B
re.c 1179 e$B9TL$Ne(B “broken string” e$B$d!"e(B
parse.y e$B$Ne(B “invalid …” e$B$,F1$8<oN`$G$9$M!#e(B

    rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);

e$B$3$l$Oe(B encode e$B%a%>%I$KEj$2$?0z?t$N?t$,0c$&$H$$$&$3$H$G!"B?J,e(B ArgError e$B$G$$$$$@$m$&!#e(B

e$B$=$&$G$9$M!#e(B

    rb_raise(rb_eArgError, "transcoding not supported (from %s to %s)", from_e, to_e);

e$B$3$l$O3d$j$He(B rescue e$B$9$k$N$,B?$$$N$G$O$J$$$+$H;W$$$^$9e(B (e$BNc$($P2?$+FC<l$Je(B encoding
e$B$XJQ49$7$F$$F!"$3$l$,$@$a$G$7$?$iF1$87ONs$N$b$C$H%Y!<%8%C%/$J$b$N$r$d$C$F$$k$H$+e(B)
e$B$J$N$G!"$b$7$+$7$F6hJL$7$F$b$$$$$N$+$J!#e(B

e$B$G$9$M!"JL$K$7$F$b$$$$$+$b$7$l$^$;$s!#e(B
UnsupportedConversion ?

    rb_raise(rb_eArgError, "not fully converted, %td bytes left", sp+slen-fromp);

e$B$3$l$OJ8;z$,ESCf$G@Z$i$l$F$$$k>l9g$J$I5/$3$j$^$9$N$G!"e(BEncoding:: e$B2<$G$$$$$H;W$$$^$9!#e(B

e$B$&!<$s!"$I$&$G$7$g$&!#e(B
e$B%(%i!<$N$=$b$=$b$N860x$O3N$+$K0z?t$G$"$ke(BStringe$B$,IT40A4$@$+$i$J$N$G$9$,!"e(B
e$B8=>]$H$7$F$OIT40A4$J!VJQ49!W$G$9$N$G!"6hJL$7$F$b$$$$5$$,$7$^$9!#e(B
e$BLB$&$H$3$m$G$9$M!#e(B