@@ -93,7 +93,7 @@ pub fn serde_json_value_to_string(json: &serde_json::Value) -> String
93
93
match serde_json:: to_string ( & json) {
94
94
Ok ( json_string) => json_string,
95
95
Err ( err) => {
96
- error ! ( "Error: Failed to convert JSON to string: {err}" ) ;
96
+ error ! ( "{}: {err}" , t! ( "util.failedToConvertJsonToString" ) ) ;
97
97
exit ( EXIT_DSC_ERROR ) ;
98
98
}
99
99
}
@@ -153,7 +153,7 @@ pub fn add_type_name_to_json(json: String, type_name: String) -> String
153
153
match add_fields_to_json ( & j, & map) {
154
154
Ok ( json) => json,
155
155
Err ( err) => {
156
- error ! ( "JSON Error : {err}" ) ;
156
+ error ! ( "JSON: {err}" ) ;
157
157
exit ( EXIT_JSON_ERROR ) ;
158
158
}
159
159
}
@@ -233,14 +233,14 @@ pub fn write_output(json: &str, format: Option<&OutputFormat>) {
233
233
let value: serde_json:: Value = match serde_json:: from_str ( json) {
234
234
Ok ( value) => value,
235
235
Err ( err) => {
236
- error ! ( "JSON Error : {err}" ) ;
236
+ error ! ( "JSON: {err}" ) ;
237
237
exit ( EXIT_JSON_ERROR ) ;
238
238
}
239
239
} ;
240
240
match serde_json:: to_string_pretty ( & value) {
241
241
Ok ( json) => json,
242
242
Err ( err) => {
243
- error ! ( "JSON Error : {err}" ) ;
243
+ error ! ( "JSON: {err}" ) ;
244
244
exit ( EXIT_JSON_ERROR ) ;
245
245
}
246
246
}
@@ -250,14 +250,14 @@ pub fn write_output(json: &str, format: Option<&OutputFormat>) {
250
250
let value: serde_json:: Value = match serde_json:: from_str ( json) {
251
251
Ok ( value) => value,
252
252
Err ( err) => {
253
- error ! ( "JSON Error : {err}" ) ;
253
+ error ! ( "JSON: {err}" ) ;
254
254
exit ( EXIT_JSON_ERROR ) ;
255
255
}
256
256
} ;
257
257
match serde_yaml:: to_string ( & value) {
258
258
Ok ( yaml) => yaml,
259
259
Err ( err) => {
260
- error ! ( "YAML Error : {err}" ) ;
260
+ error ! ( "YAML: {err}" ) ;
261
261
exit ( EXIT_JSON_ERROR ) ;
262
262
}
263
263
}
@@ -329,7 +329,7 @@ pub fn enable_tracing(trace_level_arg: Option<&TraceLevel>, trace_format_arg: Op
329
329
}
330
330
}
331
331
} else {
332
- error ! ( "Could not read 'tracing' setting" ) ;
332
+ error ! ( "{}" , t! ( "util.failedToReadTracingSetting" ) ) ;
333
333
}
334
334
335
335
// 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
342
342
"DEBUG" => TraceLevel :: Debug ,
343
343
"TRACE" => TraceLevel :: Trace ,
344
344
_ => {
345
- warn ! ( "Invalid DSC_TRACE_LEVEL value '{level}', defaulting to 'warn'" ) ;
345
+ warn ! ( "{}: '{level}'" , t! ( "util.invalidTraceLevel" ) ) ;
346
346
TraceLevel :: Warn
347
347
}
348
348
}
@@ -408,7 +408,7 @@ pub fn enable_tracing(trace_level_arg: Option<&TraceLevel>, trace_format_arg: Op
408
408
409
409
drop ( default_guard) ;
410
410
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" ) ) ;
412
412
}
413
413
414
414
// set DSC_TRACE_LEVEL for child processes
@@ -432,18 +432,18 @@ pub fn enable_tracing(trace_level_arg: Option<&TraceLevel>, trace_format_arg: Op
432
432
///
433
433
/// * `DscError` - The JSON is invalid
434
434
pub fn validate_json ( source : & str , schema : & Value , json : & Value ) -> Result < ( ) , DscError > {
435
- debug ! ( "Validating {source} against schema" ) ;
435
+ debug ! ( "{}: {source}" , t! ( "util.validatingSchema" ) ) ;
436
436
trace ! ( "JSON: {json}" ) ;
437
437
trace ! ( "Schema: {schema}" ) ;
438
438
let compiled_schema = match Validator :: new ( schema) {
439
439
Ok ( compiled_schema) => compiled_schema,
440
440
Err ( err) => {
441
- return Err ( DscError :: Validation ( format ! ( "JSON Schema Compilation Error : {err}" ) ) ) ;
441
+ return Err ( DscError :: Validation ( format ! ( "{} : {err}" , t! ( "util.failedToCompileSchema ") ) ) ;
442
442
}
443
443
} ;
444
444
445
445
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 ") ) ) ;
447
447
} ;
448
448
449
449
Ok ( ( ) )
@@ -452,19 +452,19 @@ pub fn validate_json(source: &str, schema: &Value, json: &Value) -> Result<(), D
452
452
pub fn get_input ( input : Option < & String > , file : Option < & String > ) -> String {
453
453
trace ! ( "Input: {input:?}, File: {file:?}" ) ;
454
454
let value = if let Some ( input) = input {
455
- debug ! ( "Reading input from command line parameter" ) ;
455
+ debug ! ( "{}" , t! ( "util.readingInput" ) ) ;
456
456
457
457
// see if user accidentally passed in a file path
458
458
if Path :: new ( input) . exists ( ) {
459
- error ! ( "Error: Document provided is a file path, use '--file' instead" ) ;
459
+ error ! ( "{}" , t! ( "util.inputIsFile" ) ) ;
460
460
exit ( EXIT_INVALID_INPUT ) ;
461
461
}
462
462
input. clone ( )
463
463
} else if let Some ( path) = file {
464
- debug ! ( "Reading input from file { }" , path ) ;
464
+ debug ! ( "{} {path }" , t! ( "util.readingInputFromFile" ) ) ;
465
465
// check if need to read from STDIN
466
466
if path == "-" {
467
- info ! ( "Reading input from STDIN" ) ;
467
+ info ! ( "{}" , t! ( "util.readingInputFromStdin" ) ) ;
468
468
let mut stdin = Vec :: < u8 > :: new ( ) ;
469
469
match std:: io:: stdin ( ) . read_to_end ( & mut stdin) {
470
470
Ok ( _) => {
@@ -473,13 +473,13 @@ pub fn get_input(input: Option<&String>, file: Option<&String>) -> String {
473
473
input
474
474
} ,
475
475
Err ( err) => {
476
- error ! ( "Error: Invalid utf-8 input: {err}" ) ;
476
+ error ! ( "{}: {err}" , t! ( "util.invalidUtf8" ) ) ;
477
477
exit ( EXIT_INVALID_INPUT ) ;
478
478
}
479
479
}
480
480
} ,
481
481
Err ( err) => {
482
- error ! ( "Error: Failed to read input from STDIN: {err}" ) ;
482
+ error ! ( "{}: {err}" , t! ( "util.failedToReadStdin" ) ) ;
483
483
exit ( EXIT_INVALID_INPUT ) ;
484
484
}
485
485
}
@@ -489,25 +489,25 @@ pub fn get_input(input: Option<&String>, file: Option<&String>) -> String {
489
489
input
490
490
} ,
491
491
Err ( err) => {
492
- error ! ( "Error: Failed to read input file: {err}" ) ;
492
+ error ! ( "{}: {err}" , t! ( "util.failedToReadFile" ) ) ;
493
493
exit ( EXIT_INVALID_INPUT ) ;
494
494
}
495
495
}
496
496
}
497
497
} else {
498
- debug ! ( "No input provided" ) ;
498
+ debug ! ( "{}" , t! ( "util.noInput" ) ) ;
499
499
return String :: new ( ) ;
500
500
} ;
501
501
502
502
if value. trim ( ) . is_empty ( ) {
503
- error ! ( "Provided input is empty" ) ;
503
+ error ! ( "{}" , t! ( "util.emptyInput" ) ) ;
504
504
exit ( EXIT_INVALID_INPUT ) ;
505
505
}
506
506
507
507
match parse_input_to_json ( & value) {
508
508
Ok ( json) => json,
509
509
Err ( err) => {
510
- error ! ( "Error: Invalid JSON or YAML: {err}" ) ;
510
+ error ! ( "{}: {err}" , t! ( "util.failedToParseInput" ) ) ;
511
511
exit ( EXIT_INVALID_INPUT ) ;
512
512
}
513
513
}
@@ -529,14 +529,14 @@ pub fn set_dscconfigroot(config_path: &str) -> String
529
529
530
530
// make path absolute
531
531
let Ok ( full_path) = path. absolutize ( ) else {
532
- error ! ( "Error making config path absolute" ) ;
532
+ error ! ( "{}" , t! ( "util.failedToAbsolutizePath" ) ) ;
533
533
exit ( EXIT_DSC_ERROR ) ;
534
534
} ;
535
535
536
536
let config_root_path = if full_path. is_file ( ) {
537
537
let Some ( config_root_path) = full_path. parent ( ) else {
538
538
// this should never happen because path was made absolute
539
- error ! ( "Error reading config path parent" ) ;
539
+ error ! ( "{}" , t! ( "util.failedToGetParentPath" ) ) ;
540
540
exit ( EXIT_DSC_ERROR ) ;
541
541
} ;
542
542
config_root_path. to_string_lossy ( ) . into_owned ( )
@@ -546,11 +546,11 @@ pub fn set_dscconfigroot(config_path: &str) -> String
546
546
547
547
// warn if env var is already set/used
548
548
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" ) ) ;
550
550
}
551
551
552
552
// 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" ) ) ;
554
554
env:: set_var ( DSC_CONFIG_ROOT , config_root_path) ;
555
555
556
556
full_path. to_string_lossy ( ) . into_owned ( )
0 commit comments