Skip to content

Commit

Permalink
Error handling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshi7190 committed Sep 2, 2024
1 parent 0907cc1 commit 72ff456
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 24 deletions.
42 changes: 33 additions & 9 deletions nusamai/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ fn main() -> ExitCode {
sink_provider.create(&sink_params)
};

let mut had_error = false;

let updated_transformer_registry = TransformerRegistry {
configs: transformer_registry
.configs
Expand All @@ -177,28 +179,50 @@ fn main() -> ExitCode {
match &mut config.parameter {

Check warning on line 179 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L179

Added line #L179 was not covered by tests
// If the parameter is of type Selection, update the selected value
ParameterType::Selection(selection) => {
if let Err(err) = selection.set_selected_value(value) {
eprintln!("{} for option '{}'", err, config.key);
if let Err(_err) = selection.set_selected_value(value) {
let available_options: Vec<String> = selection.get_options()
.iter()
.map(|option| format!("'{}'", option.get_value()))
.collect();
log::error!(
"Non-existent value '{}' specified for option '{}'. Available options are: {}",
value,
config.key,
available_options.join(", ")

Check warning on line 191 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L181-L191

Added lines #L181 - L191 were not covered by tests
);
had_error = true;
}

Check warning on line 194 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L193-L194

Added lines #L193 - L194 were not covered by tests
}
// If the parameter is of type Boolean, update the boolean value
ParameterType::Boolean(bool_param) => match value.as_str() {
"true" => *bool_param = true,
"false" => *bool_param = false,

Check warning on line 199 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L197-L199

Added lines #L197 - L199 were not covered by tests
_ => eprintln!(
"Invalid boolean value '{}' for option '{}'",
value, config.key
),
_ => {
log::error!(
"Invalid boolean value '{}' for option '{}'. Only 'true' or 'false' are allowed.",

Check warning on line 202 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L201-L202

Added lines #L201 - L202 were not covered by tests
value,
config.key
);
had_error = true;

Check warning on line 206 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L206

Added line #L206 was not covered by tests
}
},
// Handle other parameter types if needed
_ => eprintln!("Unsupported parameter type for key '{}'", config.key),
_ => {
log::error!("Unsupported parameter type for key '{}'", config.key);

Check warning on line 211 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L211

Added line #L211 was not covered by tests

had_error = true;

Check warning on line 213 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L213

Added line #L213 was not covered by tests
}
}
}
config // Return the (potentially updated) config
config

Check warning on line 217 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L217

Added line #L217 was not covered by tests
})
.collect(), // Collect all configs into a new Vec
.collect(),
};

if had_error {
return ExitCode::FAILURE;

Check warning on line 223 in nusamai/src/main.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/main.rs#L223

Added line #L223 was not covered by tests
}

let mut requirements = sink.make_requirements(updated_transformer_registry);
requirements.set_output_epsg(match args.sink.0.as_ref() {
"kml" => 6697, // temporary hack for KML output
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/cesiumtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl DataSinkProvider for CesiumTilesSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/czml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl DataSinkProvider for CzmlSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/geojson/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl DataSinkProvider for GeoJsonSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/gltf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl DataSinkProvider for GltfSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/gpkg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl DataSinkProvider for GpkgSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/kml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl DataSinkProvider for KmlSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/minecraft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl DataSinkProvider for MinecraftSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});

Check warning on line 74 in nusamai/src/sink/minecraft/mod.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/minecraft/mod.rs#L65-L74

Added lines #L65 - L74 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/mvt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl DataSinkProvider for MvtSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/obj/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl DataSinkProvider for ObjSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});

Check warning on line 108 in nusamai/src/sink/obj/mod.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/obj/mod.rs#L101-L108

Added lines #L101 - L108 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/ply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl DataSinkProvider for StanfordPlySinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/shapefile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl DataSinkProvider for ShapefileSinkProvider {
key: "use_lod".to_string(),
label: "出力LODの選択".to_string(),
parameter: transformer::ParameterType::Selection(Selection::new_lod_selections(
"max_lod",
"maxlod",
)),
requirements: vec![transformer::Requirement::UseLod(LodSelection::MaxLod)],
});
Expand Down
20 changes: 16 additions & 4 deletions nusamai/src/transformer/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ impl SelectionOptions {
value: value.to_string(),
}
}

pub fn get_label(&self) -> String {
self.label.clone()
}

Check warning on line 23 in nusamai/src/transformer/setting.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/transformer/setting.rs#L21-L23

Added lines #L21 - L23 were not covered by tests

pub fn get_value(&self) -> String {
self.value.clone()
}

Check warning on line 27 in nusamai/src/transformer/setting.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/transformer/setting.rs#L25-L27

Added lines #L25 - L27 were not covered by tests
}

#[derive(Debug, Serialize, Deserialize, Clone)]

Check warning on line 30 in nusamai/src/transformer/setting.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/transformer/setting.rs#L30

Added line #L30 was not covered by tests
Expand Down Expand Up @@ -46,8 +54,8 @@ impl Selection {
pub fn new_lod_selections(selected_value: &str) -> Self {
Self::new(
vec![
("最大LOD", "max_lod"),
("最小LOD", "min_lod"),
("最大LOD", "maxlod"),
("最小LOD", "minlod"),
("LOD0", "lod0"),
("LOD1", "lod1"),
("LOD2", "lod2"),
Expand All @@ -66,6 +74,10 @@ impl Selection {
Err("Invalid value".to_string())

Check warning on line 74 in nusamai/src/transformer/setting.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/transformer/setting.rs#L74

Added line #L74 was not covered by tests
}
}

Check warning on line 76 in nusamai/src/transformer/setting.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/transformer/setting.rs#L76

Added line #L76 was not covered by tests

pub fn get_options(&self) -> Vec<SelectionOptions> {
self.options.clone()
}

Check warning on line 80 in nusamai/src/transformer/setting.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/transformer/setting.rs#L78-L80

Added lines #L78 - L80 were not covered by tests
}

#[derive(Debug, Serialize, Deserialize, Clone)]

Check warning on line 83 in nusamai/src/transformer/setting.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/transformer/setting.rs#L83

Added line #L83 was not covered by tests
Expand Down Expand Up @@ -160,13 +172,13 @@ impl TransformerRegistry {
ParameterType::Selection(value) => {
if config.key == "use_lod" {
match value.selected_value.as_str() {
"max_lod" => {
"maxlod" => {
data_requirements.set_lod_filter(transformer::LodFilterSpec {
mode: transformer::LodFilterMode::Highest,
..Default::default()
})
}
"min_lod" => {
"minlod" => {
data_requirements.set_lod_filter(transformer::LodFilterSpec {
mode: transformer::LodFilterMode::Lowest,
..Default::default()
Expand Down

0 comments on commit 72ff456

Please sign in to comment.