Skip to content

Commit

Permalink
CGW refactoring: logging and error handling!
Browse files Browse the repository at this point in the history
  • Loading branch information
SviatoslavBoichuk committed Oct 2, 2024
1 parent ff69bf4 commit 581ac4d
Show file tree
Hide file tree
Showing 18 changed files with 500 additions and 429 deletions.
91 changes: 35 additions & 56 deletions src/cgw_app_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ impl CGWWSSArgs {
let wss_t_num: usize = match env::var("DEFAULT_WSS_THREAD_NUM") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse DEFAULT_WSS_THREAD_NUM! Invalid value: {}",
val
"Failed to parse DEFAULT_WSS_THREAD_NUM! Invalid value: {val}! Error: {e}"
)));
}
},
Expand All @@ -82,10 +81,9 @@ impl CGWWSSArgs {
let wss_ip: Ipv4Addr = match env::var("CGW_WSS_IP") {
Ok(val) => match Ipv4Addr::from_str(val.as_str()) {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_WSS_IP! Invalid value: {}",
val
"Failed to parse CGW_WSS_IP! Invalid value: {val}! Error: {e}"
)));
}
},
Expand All @@ -95,10 +93,9 @@ impl CGWWSSArgs {
let wss_port: u16 = match env::var("CGW_WSS_PORT") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_WSS_PORT! Invalid value: {}",
val
"Failed to parse CGW_WSS_PORT! Invalid value: {val}! Error: {e}"
)));
}
},
Expand Down Expand Up @@ -141,10 +138,9 @@ impl CGWGRPCArgs {
let grpc_listening_ip: Ipv4Addr = match env::var("CGW_GRPC_LISTENING_IP") {
Ok(val) => match Ipv4Addr::from_str(val.as_str()) {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_GRPC_LISTENING_IP! Invalid value: {}",
val
"Failed to parse CGW_GRPC_LISTENING_IP! Invalid value: {val}! Error: {e}"
)));
}
},
Expand All @@ -154,10 +150,9 @@ impl CGWGRPCArgs {
let grpc_listening_port: u16 = match env::var("CGW_GRPC_LISTENING_PORT") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_GRPC_LISTENING_PORT! Invalid value: {}",
val
"Failed to parse CGW_GRPC_LISTENING_PORT! Invalid value: {val}! Error: {e}"
)));
}
},
Expand All @@ -181,10 +176,9 @@ impl CGWGRPCArgs {
let grpc_public_port: u16 = match env::var("CGW_GRPC_PUBLIC_PORT") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_GRPC_PUBLIC_PORT! Invalid value: {}",
val
"Failed to parse CGW_GRPC_PUBLIC_PORT! Invalid value: {val}! Error: {e}"
)));
}
},
Expand Down Expand Up @@ -232,10 +226,9 @@ impl CGWKafkaArgs {
let kafka_port: u16 = match env::var("CGW_KAFKA_PORT") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_KAFKA_PORT! Invalid value: {}",
val
"Failed to parse CGW_KAFKA_PORT! Invalid value: {val}! Error: {e}"
)));
}
},
Expand Down Expand Up @@ -290,10 +283,9 @@ impl CGWDBArgs {
let db_port: u16 = match env::var("CGW_DB_PORT") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_DB_PORT! Invalid value: {}",
val
"Failed to parse CGW_DB_PORT! Invalid value: {val}! Error: {e}"
)));
}
},
Expand Down Expand Up @@ -352,10 +344,9 @@ impl CGWRedisArgs {
let redis_port: u16 = match env::var("CGW_REDIS_PORT") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_REDIS_PORT! Invalid value: {}",
val
"Failed to parse CGW_REDIS_PORT! Invalid value: {val}! Error: {e}"
)));
}
},
Expand Down Expand Up @@ -408,10 +399,9 @@ impl CGWMetricsArgs {
let metrics_port: u16 = match env::var("CGW_METRICS_PORT") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_METRICS_PORT! Invalid value: {}",
val
"Failed to parse CGW_METRICS_PORT! Invalid value: {val}! Error: {e}"
)));
}
},
Expand Down Expand Up @@ -447,8 +437,7 @@ impl CGWValidationSchemaArgs {
Ok(path) => CGWValionSchemaRef::SchemaPath(path),
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_UCENTRAL_AP_DATAMODEL_URI! Invalid URI: {}, err: {}",
uri, e
"Failed to parse CGW_UCENTRAL_AP_DATAMODEL_URI! Invalid URI: {uri}! Error: {e}"
)));
}
}
Expand All @@ -457,8 +446,7 @@ impl CGWValidationSchemaArgs {
Ok(url) => CGWValionSchemaRef::SchemaUri(url),
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_UCENTRAL_AP_DATAMODEL_URI! Invalid URI: {}, err: {}",
uri, e
"Failed to parse CGW_UCENTRAL_AP_DATAMODEL_URI! Invalid URI: {uri}! Error: {e}"
)));
}
}
Expand All @@ -470,8 +458,7 @@ impl CGWValidationSchemaArgs {
Ok(uri) => CGWValionSchemaRef::SchemaUri(uri),
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse default CGW_UCENTRAL_AP_DATAMODEL_URI! Invalid URI: {}, err: {}",
CGW_DEFAULT_UCENTRAL_AP_DATAMODEL_URI, e
"Failed to parse default CGW_UCENTRAL_AP_DATAMODEL_URI! Invalid URI: {CGW_DEFAULT_UCENTRAL_AP_DATAMODEL_URI}! Error: {e}"
)));
}
},
Expand All @@ -487,8 +474,7 @@ impl CGWValidationSchemaArgs {
Ok(path) => CGWValionSchemaRef::SchemaPath(path),
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_UCENTRAL_SWITCH_DATAMODEL_URI! Invalid URI: {}, err: {}",
uri, e
"Failed to parse CGW_UCENTRAL_SWITCH_DATAMODEL_URI! Invalid URI: {uri}! Error: {e}"
)));
}
}
Expand All @@ -497,8 +483,7 @@ impl CGWValidationSchemaArgs {
Ok(url) => CGWValionSchemaRef::SchemaUri(url),
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_UCENTRAL_SWITCH_DATAMODEL_URI! Invalid URI: {}, err: {}",
uri, e
"Failed to parse CGW_UCENTRAL_SWITCH_DATAMODEL_URI! Invalid URI: {uri}! Error: {e}"
)));
}
}
Expand All @@ -509,8 +494,7 @@ impl CGWValidationSchemaArgs {
Ok(url) => CGWValionSchemaRef::SchemaUri(url),
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse default CGW_UCENTRAL_SWITCH_DATAMODEL_URI! Invalid value: {}, err: {}",
CGW_DEFAULT_UCENTRAL_SWITCH_DATAMODEL_URI, e
"Failed to parse default CGW_UCENTRAL_SWITCH_DATAMODEL_URI! Invalid value: {CGW_DEFAULT_UCENTRAL_SWITCH_DATAMODEL_URI}! Error: {e}"
)));
}
},
Expand Down Expand Up @@ -567,8 +551,7 @@ impl AppArgs {
Ok(v) => v,
Err(_e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_LOG_LEVEL! Invalid value: {}",
val
"Failed to parse CGW_LOG_LEVEL! Invalid value: {val}! Error: (unknown)"
)));
}
},
Expand All @@ -578,10 +561,9 @@ impl AppArgs {
let cgw_id: i32 = match env::var("CGW_ID") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_ID! Invalid value: {}",
val
"Failed to parse CGW_ID! Invalid value: {val}! Error: {e}"
)));
}
},
Expand All @@ -591,10 +573,9 @@ impl AppArgs {
let cgw_groups_capacity: i32 = match env::var("CGW_GROUPS_CAPACITY") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_GROUPS_CAPACITY! Invalid value: {}",
val
"Failed to parse CGW_GROUPS_CAPACITY! Invalid value: {val}! Error: {e}"
)));
}
},
Expand All @@ -604,10 +585,9 @@ impl AppArgs {
let cgw_groups_threshold: i32 = match env::var("CGW_GROUPS_THRESHOLD") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_GROUPS_CAPACITY! Invalid value: {}",
val
"Failed to parse CGW_GROUPS_CAPACITY! Invalid value: {val}! Error: {e}"
)));
}
},
Expand All @@ -617,10 +597,9 @@ impl AppArgs {
let cgw_group_infras_capacity: i32 = match env::var("CGW_GROUP_INFRAS_CAPACITY") {
Ok(val) => match val.parse() {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(Error::AppArgsParser(format!(
"Failed to parse CGW_GROUP_INFRAS_CAPACITY! Invalid value: {}",
val
"Failed to parse CGW_GROUP_INFRAS_CAPACITY! Invalid value: {val}! Error: {e}"
)));
}
},
Expand Down
Loading

0 comments on commit 581ac4d

Please sign in to comment.