Skip to content

Commit

Permalink
sinkでのエラーハンドリング: gpkg (#434)
Browse files Browse the repository at this point in the history
パニックせず、エラーを返す。

close #421 


## 例

問題が発生しパニックになるluseデータ #398 を入力とした場合:

パニックにはならない。以下のログが出力される。

GUIまではエラーがたどり着いておらず「完了しました」とダイアログが出る。

```
[2024-03-08][05:33:08][INFO][app] Running pipeline with input: ["/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533926_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533945_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533955_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533936_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533956_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533935_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533925_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533946_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533947_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533934_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533957_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533937_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533954_luse_6668_2_op.gml", "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533944_luse_6668_2_op.gml"]
[2024-03-08][05:33:08][INFO][nusamai::pipeline::runner] Source thread started.
[2024-03-08][05:33:08][INFO][nusamai::pipeline::runner] Transformer thread started.
[2024-03-08][05:33:08][INFO][nusamai::pipeline::runner] Sink thread started.
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533926_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533946_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533936_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533947_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533955_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533934_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533944_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533945_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533937_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533935_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533954_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533957_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533956_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][INFO][nusamai::source::citygml] Parsing CityGML file: "/Users/sorami/Desktop/plateau/13100_tokyo23-ku_2022_citygml_1_2_op/udx/luse/533925_luse_6668_2_op.gml" ...
[2024-03-08][05:33:08][WARN][nusamai::sink::gpkg::table] TypeDef::Feature - Unsupported attribute type: Point ('location')
[2024-03-08][05:33:08][WARN][nusamai::sink::gpkg::table] TypeDef::Feature - Unsupported attribute type: Point ('startPoint')
[2024-03-08][05:33:08][WARN][nusamai::sink::gpkg::table] TypeDef::Feature - Unsupported attribute type: Point ('endPoint')
[2024-03-08][05:33:08][WARN][nusamai::sink::gpkg::table] TypeDef::Feature - Unsupported attribute type: Point ('origin')
[2024-03-08][05:33:08][WARN][nusamai::sink::gpkg::table] TypeDef::Feature - Unsupported attribute type: Point ('elevationValue')
[2024-03-08][05:33:08][WARN][nusamai::sink::gpkg::table] TypeDef::Feature - Unsupported attribute type: Point ('pos')
[2024-03-08][05:33:08][INFO][app] Feedback message from the pipeline FeedbackMessage { message: "Fatal error", error: Some(Other("SQLx error: error returned from database: (code: 1) duplicate column name: id")) }
[2024-03-08][05:33:08][INFO][nusamai::pipeline::runner] Source thread finished.
[2024-03-08][05:33:08][INFO][app] Feedback message from the pipeline FeedbackMessage { message: "Fatal error", error: Some(Canceled) }
[2024-03-08][05:33:08][INFO][nusamai::pipeline::runner] Sink thread finished.
[2024-03-08][05:33:08][INFO][app] Feedback message from the pipeline FeedbackMessage { message: "Fatal error", error: Some(Canceled) }
[2024-03-08][05:33:08][INFO][nusamai::pipeline::runner] Transformer thread finished.
[2024-03-08][05:33:08][INFO][app] Pipeline canceled
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **リファクタリング**
	- エラーハンドリングを改善し、`PipelineError`型を使用してエラーを適切に処理するように変更しました。

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
sorami authored Mar 8, 2024
1 parent 97e5022 commit 6e41959
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions nusamai/src/sink/gpkg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl GpkgSink {
// this is mainly expected to be used with `sqlite::memory:` for the testing purpose
GpkgHandler::from_url(&Url::parse(self.output_path.to_str().unwrap()).unwrap())
.await
.unwrap()
.map_err(|e| PipelineError::Other(e.to_string()))?
} else {
// delete the db file first is already exists
if self.output_path.exists() {
Expand All @@ -103,7 +103,7 @@ impl GpkgSink {
&Url::parse(&format!("sqlite://{}", self.output_path.to_str().unwrap())).unwrap(),
)
.await
.unwrap()
.map_err(|e| PipelineError::Other(e.to_string()))?
};

let table_infos = schema_to_table_infos(schema);
Expand Down Expand Up @@ -204,13 +204,18 @@ impl GpkgSink {
})
};

let mut tx = handler.begin().await.unwrap();
let mut tx = handler
.begin()
.await
.map_err(|e| PipelineError::Other(e.to_string()))?;
while let Some((table_name, record)) = receiver.recv().await {
feedback.ensure_not_canceled()?;

if !created_tables.contains(&table_name) {
let tf = table_infos.get(&table_name).unwrap();
tx.add_table(tf, srs_id).await.unwrap();
tx.add_table(tf, srs_id)
.await
.map_err(|e| PipelineError::Other(e.to_string()))?;
created_tables.insert(table_name.clone());
}

Expand All @@ -223,20 +228,26 @@ impl GpkgSink {
} => {
tx.insert_feature(&table_name, &obj_id, &geometry, &attributes)
.await
.unwrap();
.map_err(|e| PipelineError::Other(e.to_string()))?;
table_bboxes.entry(table_name).or_default().merge(&bbox);
}
Record::Attribute { attributes } => {
tx.insert_attribute(&table_name, &attributes).await.unwrap();
tx.insert_attribute(&table_name, &attributes)
.await
.map_err(|e| PipelineError::Other(e.to_string()))?;
}
}
}

for (table_name, bbox) in table_bboxes {
tx.update_bbox(&table_name, bbox.to_tuple()).await.unwrap();
tx.update_bbox(&table_name, bbox.to_tuple())
.await
.map_err(|e| PipelineError::Other(e.to_string()))?;
}

tx.commit().await.unwrap();
tx.commit()
.await
.map_err(|e| PipelineError::Other(e.to_string()))?;

match producers.await.unwrap() {
Ok(_) | Err(PipelineError::Canceled) => Ok(()),
Expand Down

0 comments on commit 6e41959

Please sign in to comment.