Skip to content

Commit 22d57e5

Browse files
committed
missed changes
1 parent 978e6cb commit 22d57e5

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

dsc/src/util.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn serde_json_value_to_string(json: &serde_json::Value) -> String
9393
match serde_json::to_string(&json) {
9494
Ok(json_string) => json_string,
9595
Err(err) => {
96-
error!("Error: Failed to convert JSON to string: {err}");
96+
error!("{}: {err}", t!("util.failedToConvertJsonToString"));
9797
exit(EXIT_DSC_ERROR);
9898
}
9999
}
@@ -153,7 +153,7 @@ pub fn add_type_name_to_json(json: String, type_name: String) -> String
153153
match add_fields_to_json(&j, &map) {
154154
Ok(json) => json,
155155
Err(err) => {
156-
error!("JSON Error: {err}");
156+
error!("JSON: {err}");
157157
exit(EXIT_JSON_ERROR);
158158
}
159159
}
@@ -233,14 +233,14 @@ pub fn write_output(json: &str, format: Option<&OutputFormat>) {
233233
let value: serde_json::Value = match serde_json::from_str(json) {
234234
Ok(value) => value,
235235
Err(err) => {
236-
error!("JSON Error: {err}");
236+
error!("JSON: {err}");
237237
exit(EXIT_JSON_ERROR);
238238
}
239239
};
240240
match serde_json::to_string_pretty(&value) {
241241
Ok(json) => json,
242242
Err(err) => {
243-
error!("JSON Error: {err}");
243+
error!("JSON: {err}");
244244
exit(EXIT_JSON_ERROR);
245245
}
246246
}
@@ -250,14 +250,14 @@ pub fn write_output(json: &str, format: Option<&OutputFormat>) {
250250
let value: serde_json::Value = match serde_json::from_str(json) {
251251
Ok(value) => value,
252252
Err(err) => {
253-
error!("JSON Error: {err}");
253+
error!("JSON: {err}");
254254
exit(EXIT_JSON_ERROR);
255255
}
256256
};
257257
match serde_yaml::to_string(&value) {
258258
Ok(yaml) => yaml,
259259
Err(err) => {
260-
error!("YAML Error: {err}");
260+
error!("YAML: {err}");
261261
exit(EXIT_JSON_ERROR);
262262
}
263263
}
@@ -329,7 +329,7 @@ pub fn enable_tracing(trace_level_arg: Option<&TraceLevel>, trace_format_arg: Op
329329
}
330330
}
331331
} else {
332-
error!("Could not read 'tracing' setting");
332+
error!("{}", t!("util.failedToReadTracingSetting"));
333333
}
334334

335335
// override with DSC_TRACE_LEVEL env var if permitted
@@ -342,7 +342,7 @@ pub fn enable_tracing(trace_level_arg: Option<&TraceLevel>, trace_format_arg: Op
342342
"DEBUG" => TraceLevel::Debug,
343343
"TRACE" => TraceLevel::Trace,
344344
_ => {
345-
warn!("Invalid DSC_TRACE_LEVEL value '{level}', defaulting to 'warn'");
345+
warn!("{}: '{level}'", t!("util.invalidTraceLevel"));
346346
TraceLevel::Warn
347347
}
348348
}
@@ -408,7 +408,7 @@ pub fn enable_tracing(trace_level_arg: Option<&TraceLevel>, trace_format_arg: Op
408408

409409
drop(default_guard);
410410
if tracing::subscriber::set_global_default(subscriber).is_err() {
411-
eprintln!("Unable to set global default tracing subscriber. Tracing is diabled.");
411+
eprintln!("{}", t!("util.failedToSetTracing"));
412412
}
413413

414414
// set DSC_TRACE_LEVEL for child processes
@@ -432,18 +432,18 @@ pub fn enable_tracing(trace_level_arg: Option<&TraceLevel>, trace_format_arg: Op
432432
///
433433
/// * `DscError` - The JSON is invalid
434434
pub fn validate_json(source: &str, schema: &Value, json: &Value) -> Result<(), DscError> {
435-
debug!("Validating {source} against schema");
435+
debug!("{}: {source}", t!("util.validatingSchema"));
436436
trace!("JSON: {json}");
437437
trace!("Schema: {schema}");
438438
let compiled_schema = match Validator::new(schema) {
439439
Ok(compiled_schema) => compiled_schema,
440440
Err(err) => {
441-
return Err(DscError::Validation(format!("JSON Schema Compilation Error: {err}")));
441+
return Err(DscError::Validation(format!("{}: {err}", t!("util.failedToCompileSchema")));
442442
}
443443
};
444444

445445
if let Err(err) = compiled_schema.validate(json) {
446-
return Err(DscError::Validation(format!("'{source}' failed validation: {err}")));
446+
return Err(DscError::Validation(format!("{}: '{source}' {err}", t!("util.validationFailed")));
447447
};
448448

449449
Ok(())
@@ -452,19 +452,19 @@ pub fn validate_json(source: &str, schema: &Value, json: &Value) -> Result<(), D
452452
pub fn get_input(input: Option<&String>, file: Option<&String>) -> String {
453453
trace!("Input: {input:?}, File: {file:?}");
454454
let value = if let Some(input) = input {
455-
debug!("Reading input from command line parameter");
455+
debug!("{}", t!("util.readingInput"));
456456

457457
// see if user accidentally passed in a file path
458458
if Path::new(input).exists() {
459-
error!("Error: Document provided is a file path, use '--file' instead");
459+
error!("{}", t!("util.inputIsFile"));
460460
exit(EXIT_INVALID_INPUT);
461461
}
462462
input.clone()
463463
} else if let Some(path) = file {
464-
debug!("Reading input from file {}", path);
464+
debug!("{} {path}", t!("util.readingInputFromFile"));
465465
// check if need to read from STDIN
466466
if path == "-" {
467-
info!("Reading input from STDIN");
467+
info!("{}", t!("util.readingInputFromStdin"));
468468
let mut stdin = Vec::<u8>::new();
469469
match std::io::stdin().read_to_end(&mut stdin) {
470470
Ok(_) => {
@@ -473,13 +473,13 @@ pub fn get_input(input: Option<&String>, file: Option<&String>) -> String {
473473
input
474474
},
475475
Err(err) => {
476-
error!("Error: Invalid utf-8 input: {err}");
476+
error!("{}: {err}", t!("util.invalidUtf8"));
477477
exit(EXIT_INVALID_INPUT);
478478
}
479479
}
480480
},
481481
Err(err) => {
482-
error!("Error: Failed to read input from STDIN: {err}");
482+
error!("{}: {err}", t!("util.failedToReadStdin"));
483483
exit(EXIT_INVALID_INPUT);
484484
}
485485
}
@@ -489,25 +489,25 @@ pub fn get_input(input: Option<&String>, file: Option<&String>) -> String {
489489
input
490490
},
491491
Err(err) => {
492-
error!("Error: Failed to read input file: {err}");
492+
error!("{}: {err}", t!("util.failedToReadFile"));
493493
exit(EXIT_INVALID_INPUT);
494494
}
495495
}
496496
}
497497
} else {
498-
debug!("No input provided");
498+
debug!("{}", t!("util.noInput"));
499499
return String::new();
500500
};
501501

502502
if value.trim().is_empty() {
503-
error!("Provided input is empty");
503+
error!("{}", t!("util.emptyInput"));
504504
exit(EXIT_INVALID_INPUT);
505505
}
506506

507507
match parse_input_to_json(&value) {
508508
Ok(json) => json,
509509
Err(err) => {
510-
error!("Error: Invalid JSON or YAML: {err}");
510+
error!("{}: {err}", t!("util.failedToParseInput"));
511511
exit(EXIT_INVALID_INPUT);
512512
}
513513
}
@@ -529,14 +529,14 @@ pub fn set_dscconfigroot(config_path: &str) -> String
529529

530530
// make path absolute
531531
let Ok(full_path) = path.absolutize() else {
532-
error!("Error making config path absolute");
532+
error!("{}", t!("util.failedToAbsolutizePath"));
533533
exit(EXIT_DSC_ERROR);
534534
};
535535

536536
let config_root_path = if full_path.is_file() {
537537
let Some(config_root_path) = full_path.parent() else {
538538
// this should never happen because path was made absolute
539-
error!("Error reading config path parent");
539+
error!("{}", t!("util.failedToGetParentPath"));
540540
exit(EXIT_DSC_ERROR);
541541
};
542542
config_root_path.to_string_lossy().into_owned()
@@ -546,11 +546,11 @@ pub fn set_dscconfigroot(config_path: &str) -> String
546546

547547
// warn if env var is already set/used
548548
if env::var(DSC_CONFIG_ROOT).is_ok() {
549-
warn!("The current value of '{DSC_CONFIG_ROOT}' env var will be overridden");
549+
warn!("{}", t!("util.dscConfigRootAlreadySet"));
550550
}
551551

552552
// Set env var so child processes (of resources) can use it
553-
debug!("Setting '{DSC_CONFIG_ROOT}' env var as '{config_root_path}'");
553+
debug!("{} '{config_root_path}'", t!("util.settingDscConfigRoot"));
554554
env::set_var(DSC_CONFIG_ROOT, config_root_path);
555555

556556
full_path.to_string_lossy().into_owned()

0 commit comments

Comments
 (0)