-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRS_ConsoleWarnDetails.rb
160 lines (138 loc) · 4.86 KB
/
RS_ConsoleWarnDetails.rb
1
2
3
4
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#================================================================
# The MIT License
# Copyright (c) 2020 biud436
# ---------------------------------------------------------------
# Free for commercial and non commercial use.
#================================================================
#==============================================================================
# ** 자세한 오류 출력 및 로그 저장
# Author : biud436
# Version Log :
# 2019.12.21 (v1.0.0) : First Release
# 2020.02.07 (v1.0.1) :
# - Fixed an issue about the error location.
#==============================================================================
# ** Terms of Use
#==============================================================================
# Free for commercial and non-commercial use
#==============================================================================
$imported = {} if $imported.nil?
$imported["RS_ConsoleWarnDetails"] = true
module RS
module ConsoleWarnDetails
# 오류를 기록할 디버그 로그 파일의 이름
# 바탕화면에 저장하고 싶다면 다음과 같습니다.
# 예:) File.join(ENV["HOME"], "Desktop", "debug.log")
DEBUG_FILE_NAME = "debug.log"
# 오류 시간 텍스트
TIME_FMT = "오류 시간 : %s"
# 오류 타입 텍스트
ERROR_TYPE_FMT = "오류 타입 : %s"
# 오류 스크립트 텍스트
SCRIPT_NAME_FMT = "오류가 난 스크립트 : %s"
# 오류 라인 텍스트
SCRIPT_LINE_FMT = "오류가 발생한 라인 : %d"
# 오류가 난 스크립트 토큰
SCRIPT_TOKEN_FMT = "오류가 발생한 토큰 : %s"
# 자세한 오류
SCRIPT_DETAIL_ERROR_FMT = "%s --> %d번 라인, %s에서 오류"
# 오류 메시지 텍스트
ERROR_MESSAGE_FMT = "오류 메시지 : %s"
ERROR_BACKTRACE_FMT = "오류 스택 : "
# true이면 콘솔에만 오류를 표시하고 게임을 계속 진행합니다.
# false면 오류를 전달하고 오류와 함께 게임이 종료 됩니다.
# false면 저장하지 않은 모든 데이터를 잃게 됩니다 (기본값은 false)
INLINE = false
# true이면 모든 영역에서 자세한 오류 출력
# false면 Game_Character와 Game_Interpreter에서만 자세한 오류 출력
# true을 사용하면 모든 곳에서 자세한 오류를 출력합니다.
ALL = true
def self.extract(lines, backtraces)
return if backtraces && !backtraces.is_a?(Array)
backtraces.each do |t|
if t =~ /^\{(\d+)\}\:(\d+)\:(.*)/
script_name = $RGSS_SCRIPTS[$1.to_i][1]
script_line = $2.to_i
script_token = $3.gsub!("in ", "")
lines << sprintf(SCRIPT_DETAIL_ERROR_FMT, script_name, script_line, script_token)
end
end
end
def self.trace(e)
lines = []
if $@[0].to_s =~ /^\{(\d+)\}\:(\d+)\:(.*)/
# 오류 타입 표시
lines << sprintf(ERROR_TYPE_FMT, $!.class.to_s)
lines << "----------"
script_name = $RGSS_SCRIPTS[$1.to_i][1]
script_line = $2.to_i
script_token = $3.gsub!("in ", "")
lines << sprintf(SCRIPT_DETAIL_ERROR_FMT, script_name, script_line, script_token)
end
# 오류 시간 표시
lines << sprintf(TIME_FMT, Time.now.to_s)
lines << "----------"
# 오류 메시지 표시
lines << sprintf(ERROR_MESSAGE_FMT, e.message)
lines << "----------"
lines << ERROR_BACKTRACE_FMT
self.extract(lines, e.backtrace)
lines << "----------"
f = File.open(DEBUG_FILE_NAME, "w+")
lines.each { |line| f.puts line }
f.close
f = File.open('scripts.txt', 'w+')
f.puts $RGSS_SCRIPTS
f.close
if INLINE
puts lines.join("\r\n")
else
error = StandardError.new(lines.join("\r\n"))
error.set_backtrace($@)
raise error
end
end
end
end
if RS::ConsoleWarnDetails::ALL
def rgss_main
loop do
begin
yield
break
rescue RGSSReset # F12
Audio.__reset__
Graphics.__reset__
rescue NameError => e
RS::ConsoleWarnDetails.trace(e)
rescue => e
RS::ConsoleWarnDetails.trace(e)
end
end
end
else
class Game_Character < Game_CharacterBase
alias detail_error_update_routine_move update_routine_move
def update_routine_move
begin
detail_error_update_routine_move
rescue => e
RS::ConsoleWarnDetails.trace(e)
end
end
end
class Game_Interpreter
def command_355
script = @list[@index].parameters[0] + "\n"
while next_event_code == 655
@index += 1
script += @list[@index].parameters[0] + "\n"
end
begin
eval(script)
rescue => e
RS::ConsoleWarnDetails.trace(e)
end
end
end
end