Project

General

Profile

Feature #12016

More informative error message when Symbol encoding is invalid

Added by alexdowad (Alex Dowad) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:73398]

Description

When a symbol literal is invalid in the source file's encoding, an EncodingError exception is raised, with the following message: invalid encoding symbol. This patches the interpreter so a more informative message is generated, similar to:
encoding UTF-8 is invalid for symbol :"\xC7".

Here is where this originated from: https://github.com/whitequark/parser/issues/252


Files

patch_symbol_encoding_error_msg.diff (547 Bytes) patch_symbol_encoding_error_msg.diff alexdowad (Alex Dowad), 01/25/2016 06:13 AM
patch_symbol_encoding_error_msg.diff (547 Bytes) patch_symbol_encoding_error_msg.diff Patch which adjusts error message in sym_check_asciionly alexdowad (Alex Dowad), 01/25/2016 06:13 AM

Associated revisions

Revision dfca38ea
Added by nobu (Nobuyoshi Nakada) over 3 years ago

symbol.c: more informative error message

  • symbol.c (sym_check_asciionly): more informative error message with the encoding name and the inspected content. [ruby-core:73398] [Feature #12016]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 53650
Added by nobu (Nobuyoshi Nakada) over 3 years ago

symbol.c: more informative error message

  • symbol.c (sym_check_asciionly): more informative error message with the encoding name and the inspected content. [ruby-core:73398] [Feature #12016]

Revision 53650
Added by nobu (Nobuyoshi Nakada) over 3 years ago

symbol.c: more informative error message

  • symbol.c (sym_check_asciionly): more informative error message with the encoding name and the inspected content. [ruby-core:73398] [Feature #12016]

Revision 53650
Added by nobu (Nobuyoshi Nakada) over 3 years ago

symbol.c: more informative error message

  • symbol.c (sym_check_asciionly): more informative error message with the encoding name and the inspected content. [ruby-core:73398] [Feature #12016]

Revision 53650
Added by nobu (Nobuyoshi Nakada) over 3 years ago

symbol.c: more informative error message

  • symbol.c (sym_check_asciionly): more informative error message with the encoding name and the inspected content. [ruby-core:73398] [Feature #12016]

History

Updated by normalperson (Eric Wong) over 3 years ago

alexinbeijing@gmail.com wrote:

Feature #12016: More informative error message when Symbol encoding is invalid
https://bugs.ruby-lang.org/issues/12016

Calling RSTRING_PTR on any function return value directly is dangerous
because of GC. PRI*VALUE format strings were introduced to help make
avoiding this danger easier, and the '+' modifier will call inspect for
you.

How about the following?

rb_raise(rb_eEncodingError,
    "encoding %s is invalid for symbol :%+"PRIsVALUE,

rb_enc_name(rb_enc_get(str)),
str);

(also wrapping at 80 cols, some of us use big fonts)

#2

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset r53650.


symbol.c: more informative error message

  • symbol.c (sym_check_asciionly): more informative error message with the encoding name and the inspected content. [ruby-core:73398] [Feature #12016]

Also available in: Atom PDF