Skip to content

Commit 6a5bec5

Browse files
committed
[#181] 오류 메세지 수정
1 parent 3ca3f83 commit 6a5bec5

4 files changed

Lines changed: 27 additions & 48 deletions

File tree

src/engine/actions/ddl/alter_database.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::engine::schema::database::DatabaseSchema;
88
use crate::engine::types::{
99
ExecuteColumn, ExecuteColumnType, ExecuteField, ExecuteResult, ExecuteRow,
1010
};
11-
use crate::errors::execute_error::ExecuteError;
1211
use crate::errors;
12+
use crate::errors::execute_error::ExecuteError;
1313

1414
impl DBEngine {
1515
pub async fn alter_database(&self, query: AlterDatabaseQuery) -> errors::Result<ExecuteResult> {
@@ -22,9 +22,10 @@ impl DBEngine {
2222
Some(action) => match action {
2323
AlterDatabaseAction::RenameTo(rename) => {
2424
// 기존 데이터베이스명
25-
let from_database_name = query.database_name.clone().ok_or_else(|| {
26-
ExecuteError::wrap("no database name".to_string())
27-
})?;
25+
let from_database_name = query
26+
.database_name
27+
.clone()
28+
.ok_or_else(|| ExecuteError::wrap("no database name".to_string()))?;
2829

2930
// 변경할 데이터베이스명
3031
let to_database_name = rename.name;
@@ -42,9 +43,7 @@ impl DBEngine {
4243
if let Err(error) = result {
4344
match error.kind() {
4445
IOErrorKind::NotFound => {
45-
return Err(ExecuteError::wrap(
46-
"database not found".to_string(),
47-
));
46+
return Err(ExecuteError::wrap("database not found".to_string()));
4847
}
4948
_ => {
5049
return Err(ExecuteError::wrap(
@@ -73,22 +72,18 @@ impl DBEngine {
7372
.await
7473
{
7574
return Err(ExecuteError::wrap(
76-
"no database name".to_string(),
75+
"failed to write database config",
7776
));
7877
}
7978
}
8079
None => {
81-
return Err(ExecuteError::wrap(
82-
"invalid config data".to_string(),
83-
));
80+
return Err(ExecuteError::wrap("invalid config data"));
8481
}
8582
}
8683
}
8784
Err(error) => match error.kind() {
8885
IOErrorKind::NotFound => {
89-
return Err(ExecuteError::wrap(
90-
"database not found".to_string(),
91-
));
86+
return Err(ExecuteError::wrap("database not found"));
9287
}
9388
_ => {
9489
return Err(ExecuteError::wrap(format!("{:?}", error)));

src/engine/parser/implements/ddl/database.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ use crate::engine::ast::ddl::create_database::CreateDatabaseQuery;
55
use crate::engine::ast::ddl::drop_database::{DropDatabaseQuery, SQLStatement};
66
use crate::engine::lexer::predule::Token;
77
use crate::engine::parser::predule::Parser;
8-
use crate::errors::parsing_error::ParsingError;
98
use crate::errors;
9+
use crate::errors::parsing_error::ParsingError;
1010

1111
impl Parser {
1212
// CREATE DATABASE 쿼리 분석
1313
pub(crate) fn handle_create_database_query(&mut self) -> errors::Result<SQLStatement> {
1414
if !self.has_next_token() {
15-
return Err(ParsingError::wrap(
16-
"need more tokens".to_string(),
17-
));
15+
return Err(ParsingError::wrap("need more tokens".to_string()));
1816
}
1917

2018
let mut query_builder = CreateDatabaseQuery::builder();
@@ -24,9 +22,7 @@ impl Parser {
2422
query_builder = query_builder.set_if_not_exists(if_not_exists);
2523

2624
if !self.has_next_token() {
27-
return Err(ParsingError::wrap(
28-
"need more tokens".to_string(),
29-
));
25+
return Err(ParsingError::wrap("need more tokens".to_string()));
3026
}
3127

3228
let current_token = self.get_next_token();
@@ -68,9 +64,7 @@ impl Parser {
6864

6965
// 테이블명 획득 로직
7066
if !self.has_next_token() {
71-
return Err(ParsingError::wrap(
72-
"need more tokens".to_string(),
73-
));
67+
return Err(ParsingError::wrap("need more tokens".to_string()));
7468
}
7569

7670
let current_token = self.get_next_token();
@@ -106,9 +100,7 @@ impl Parser {
106100
// ALTER DATABASE 쿼리 분석
107101
pub(crate) fn handle_alter_database_query(&mut self) -> errors::Result<SQLStatement> {
108102
if !self.has_next_token() {
109-
return Err(ParsingError::wrap(
110-
"need more tokens".to_string(),
111-
));
103+
return Err(ParsingError::wrap("need more tokens".to_string()));
112104
}
113105

114106
let mut query_builder = AlterDatabaseQuery::builder();
@@ -136,23 +128,21 @@ impl Parser {
136128
Token::Rename => {
137129
if !self.has_next_token() {
138130
return Err(ParsingError::wrap(
139-
"E106: expected 'TO'. but no more token".to_string(),
131+
"expected 'TO'. but no more token".to_string(),
140132
));
141133
}
142134

143135
let current_token = self.get_next_token();
144136

145137
if current_token != Token::To {
146138
return Err(ParsingError::wrap(format!(
147-
" expected 'TO'. but your input word is '{:?}'",
139+
"expected 'TO'. but your input word is '{:?}'",
148140
current_token
149141
)));
150142
}
151143

152144
if !self.has_next_token() {
153-
return Err(ParsingError::wrap(
154-
" expected identifier. but no more token",
155-
));
145+
return Err(ParsingError::wrap("expected identifier. but no more token"));
156146
}
157147

158148
let current_token = self.get_next_token();
@@ -165,15 +155,15 @@ impl Parser {
165155
}
166156
_ => {
167157
return Err(ParsingError::wrap(
168-
" not supported command. possible commands: (alter database)",
158+
"not supported command. possible commands: (alter database)",
169159
));
170160
}
171161
}
172162
}
173163
Token::SemiColon => {}
174164
_ => {
175165
return Err(ParsingError::wrap(format!(
176-
" not supported syntax'{:?}'",
166+
"not supported syntax'{:?}'",
177167
current_token
178168
)));
179169
}

src/engine/parser/implements/ddl/top_level.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::engine::ast::SQLStatement;
22
use crate::engine::lexer::predule::Token;
33
use crate::engine::parser::context::ParserContext;
44
use crate::engine::parser::predule::Parser;
5-
use crate::errors::parsing_error::ParsingError;
65
use crate::errors;
6+
use crate::errors::parsing_error::ParsingError;
77

88
impl Parser {
99
// CREATE...로 시작되는 쿼리 분석
@@ -12,9 +12,7 @@ impl Parser {
1212
context: ParserContext,
1313
) -> errors::Result<SQLStatement> {
1414
if !self.has_next_token() {
15-
return Err(ParsingError::wrap(
16-
"need more tokens".to_string(),
17-
));
15+
return Err(ParsingError::wrap("need more tokens".to_string()));
1816
}
1917

2018
let current_token = self.get_next_token();
@@ -23,7 +21,7 @@ impl Parser {
2321
Token::Table => self.handle_create_table_query(context),
2422
Token::Database => self.handle_create_database_query(),
2523
_ => Err(ParsingError::wrap(format!(
26-
"not supported command. possible commands: (create table). but your input is {:?}",
24+
"not supported command. possible commands: (create table, create database). but your input is {:?}",
2725
current_token
2826
))),
2927
}
@@ -35,9 +33,7 @@ impl Parser {
3533
context: ParserContext,
3634
) -> errors::Result<SQLStatement> {
3735
if !self.has_next_token() {
38-
return Err(ParsingError::wrap(
39-
"need more tokens".to_string(),
40-
));
36+
return Err(ParsingError::wrap("need more tokens".to_string()));
4137
}
4238

4339
let current_token = self.get_next_token();
@@ -46,7 +42,7 @@ impl Parser {
4642
Token::Table => self.handle_alter_table_query(context),
4743
Token::Database => self.handle_alter_database_query(),
4844
_ => Err(ParsingError::wrap(
49-
"not supported command. possible commands: (alter table)",
45+
"not supported command. possible commands: (alter table, alter database)",
5046
)),
5147
}
5248
}
@@ -56,9 +52,7 @@ impl Parser {
5652
context: ParserContext,
5753
) -> errors::Result<SQLStatement> {
5854
if !self.has_next_token() {
59-
return Err(ParsingError::wrap(
60-
"need more tokens".to_string(),
61-
));
55+
return Err(ParsingError::wrap("need more tokens".to_string()));
6256
}
6357

6458
let current_token = self.get_next_token();
@@ -67,7 +61,7 @@ impl Parser {
6761
Token::Table => self.handle_drop_table_query(context),
6862
Token::Database => self.handle_drop_database_query(),
6963
_ => Err(ParsingError::wrap(
70-
"not supported command. possible commands: (drop table)",
64+
"not supported command. possible commands: (drop table, drop database)",
7165
)),
7266
}
7367
}

src/engine/parser/implements/dml/insert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Parser {
9191
}
9292
_ => {
9393
return Err(ParsingError::wrap(format!(
94-
"expected 'Values'. but your input word is '{:?}'",
94+
"expected 'VALUES' or 'SELECT'. but your input word is '{:?}'",
9595
current_token
9696
)));
9797
}

0 commit comments

Comments
 (0)