Module: Rbpad::Error_jp

Defined in:
lib/rbpad/error_jp.rb

Class Method Summary collapse

Class Method Details

.get_msg(line) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rbpad/error_jp.rb', line 5

module_function def get_msg(line)
  /(.*):(\d+)/ =~ line
  name = $1
  pos  = $2
  msg_pos     = "ファイル #{name}#{pos}行目でエラーが発生しました。"
  msg_content = "(詳細情報は不明です)"
  if /syntax error/ =~ line
    msg_content = "syntax error"
    if    /unexpected end-of-input/ =~ line
      msg_content = %Q(プログラムの構文が途中で終わっています。)
    elsif /unexpected (keyword_)?end/ =~ line
      msg_content = %Q('end'で終わるブロックの対応が不完全です。)
    elsif /unexpected tIDENTIFIER/ =~ line
      msg_content = %Q(全角文字などの使用できない文字が混ざっています。)
    elsif /unexpected t(.*),/ =~ line
      msg_content = %Q(予期しない #{$1} が混ざっています。)
    elsif /unexpected (.*)/ =~ line
      msg_content = %Q(#{$1} という正しくないキーワードが使われています。)
    end
  elsif /\(NameError\)/ =~ line
    msg_content = "NameError"
    if    /undefined local variable or method (.*?) / =~ line
      msg_content = %Q(#{$1} という名前の変数またはメソッドが定義されていないか、タイプミスの可能性があります。)
    elsif /uninitialized constant (.*?) / =~ line
      msg_content = %Q(定数 #{$1} の値が初期化されていません。)
    end
  elsif /\(NoMethodError\)/ =~ line
    msg_content = "NoMethodError"
    if    /undefined method (.*) for (.*):(.*?) / =~ line
      msg_content = %Q(#{$3}#{$2} には #{$1} というメソッドは定義されていません。)
    end
  elsif /\(LoadError\)/ =~ line
    msg_content = "ロードできません。"
    if    /cannot load such file \-\- (.*) /=~ line
      msg_content = %Q(#{$1} というファイルが見つからないのでロードできません。)
    end
  elsif /\(ArgumentError\)/ =~ line
    msg_content = "ArgumentError"
    if    /wrong number of arguments/ =~ line
      msg_content = %Q(メソッドに渡した引数の個数が正しくありません。)
    elsif /must be positive/ =~ line
      msg_content = %Q(引数には正(プラス)の値を渡してください。)
    elsif /must not be negative/ =~ line
      msg_content = %Q(引数には負(マイナス)以外の値を渡してください。)
    end
  elsif /\(TypeError\)/ =~ line
    msg_content = "TypeError"
    if   /can't convert (.*) into (.*) \(/ =~ line
      msg_content = %Q(引数には #{$1} ではなく #{$2} を渡してください。)
    end
  else
    if    /unterminated string/ =~ line
      msg_content = %Q(文字列が '' や "" で閉じられていません。)
    elsif /unterminated regexp/ =~ line
      msg_content = %Q(正規表現が // で閉じられていません。)
    elsif /class\/module name must be CONSTANT/ =~ line
      msg_content = %Q(クラスやモジュールの名前は大文字で始めてください。)
    elsif /No such file or directory @ rb_sysopen - (.*) / =~ line
      msg_content = %Q(#{$1} というファイルまたはディレクトリ(フォルダ)は存在しないため開くことができません。)
    elsif /Invalid argument @ rb_sysopen - (.*) / =~ line
      msg_content = %Q(#{$1} というファイル名は不正なため開くことができません。)
    elsif /Is a directory @ rb_sysopen - (.*) / =~ line
      msg_content = %Q(#{$1} はディレクトリ(フォルダ)のため開くことができません。)
    end
  end
  "#{msg_pos}\n#{msg_content}"
end