Skip to content

Commit 48b1b87

Browse files
committed
fix: correct error messages for text functions
1 parent ff30ac1 commit 48b1b87

File tree

1 file changed

+30
-38
lines changed

1 file changed

+30
-38
lines changed

src/implementation/text.rs

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ fn as_bytes(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
4444
else {
4545
return Err(RuntimeError::simple(
4646
"InvalidArgumentRuntimeError",
47-
format!(
48-
"Expected two numbers as arguments but received {:?}",
49-
values
50-
),
47+
format!("Expected one string as argument but received {:?}", values),
5148
));
5249
};
5350

@@ -72,7 +69,7 @@ fn byte_size(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError
7269
return Err(RuntimeError::simple(
7370
"InvalidArgumentRuntimeError",
7471
format!(
75-
"Expected two numbers as arguments but received {:?}",
72+
"Expected one string as an argument but received {:?}",
7673
values
7774
),
7875
));
@@ -91,7 +88,7 @@ fn capitalize(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeErro
9188
return Err(RuntimeError::simple(
9289
"InvalidArgumentRuntimeError",
9390
format!(
94-
"Expected two numbers as arguments but received {:?}",
91+
"Expected one string as an argument but received {:?}",
9592
values
9693
),
9794
));
@@ -133,7 +130,7 @@ fn uppercase(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError
133130
return Err(RuntimeError::simple(
134131
"InvalidArgumentRuntimeError",
135132
format!(
136-
"Expected two numbers as arguments but received {:?}",
133+
"Expected one string as an argument but received {:?}",
137134
values
138135
),
139136
));
@@ -152,7 +149,7 @@ fn lowercase(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError
152149
return Err(RuntimeError::simple(
153150
"InvalidArgumentRuntimeError",
154151
format!(
155-
"Expected two numbers as arguments but received {:?}",
152+
"Expected one string as an argument but received {:?}",
156153
values
157154
),
158155
));
@@ -171,7 +168,7 @@ fn swapcase(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
171168
return Err(RuntimeError::simple(
172169
"InvalidArgumentRuntimeError",
173170
format!(
174-
"Expected two numbers as arguments but received {:?}",
171+
"Expected one string as an argument but received {:?}",
175172
values
176173
),
177174
));
@@ -203,7 +200,7 @@ fn chars(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
203200
return Err(RuntimeError::simple(
204201
"InvalidArgumentRuntimeError",
205202
format!(
206-
"Expected two numbers as arguments but received {:?}",
203+
"Expected one string as an argument but received {:?}",
207204
values
208205
),
209206
));
@@ -231,7 +228,7 @@ fn at(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
231228
return Err(RuntimeError::simple(
232229
"InvalidArgumentRuntimeError",
233230
format!(
234-
"Expected two numbers as arguments but received {:?}",
231+
"Expected one string followed by one number as arguments but received {:?}",
235232
values
236233
),
237234
));
@@ -273,7 +270,7 @@ fn trim(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
273270
return Err(RuntimeError::simple(
274271
"InvalidArgumentRuntimeError",
275272
format!(
276-
"Expected two numbers as arguments but received {:?}",
273+
"Expected one string as an arguments but received {:?}",
277274
values
278275
),
279276
));
@@ -293,10 +290,7 @@ fn append(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
293290
else {
294291
return Err(RuntimeError::simple(
295292
"InvalidArgumentRuntimeError",
296-
format!(
297-
"Expected two numbers as arguments but received {:?}",
298-
values
299-
),
293+
format!("Expected two numbers as argument but received {:?}", values),
300294
));
301295
};
302296

@@ -315,7 +309,7 @@ fn prepend(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
315309
return Err(RuntimeError::simple(
316310
"InvalidArgumentRuntimeError",
317311
format!(
318-
"Expected two numbers as arguments but received {:?}",
312+
"Expected two strings as arguments but received {:?}",
319313
values
320314
),
321315
));
@@ -338,7 +332,7 @@ fn insert(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
338332
return Err(RuntimeError::simple(
339333
"InvalidArgumentRuntimeError",
340334
format!(
341-
"Expected two numbers as arguments but received {:?}",
335+
"Expected string, number, and string as arguments but received {:?}",
342336
values
343337
),
344338
));
@@ -361,7 +355,7 @@ fn length(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
361355
return Err(RuntimeError::simple(
362356
"InvalidArgumentRuntimeError",
363357
format!(
364-
"Expected two numbers as arguments but received {:?}",
358+
"Expected one string as an argument but received {:?}",
365359
values
366360
),
367361
));
@@ -384,7 +378,7 @@ fn remove(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
384378
return Err(RuntimeError::simple(
385379
"InvalidArgumentRuntimeError",
386380
format!(
387-
"Expected two numbers as arguments but received {:?}",
381+
"Expected one string followed by two numbers as arguments but received {:?}",
388382
values
389383
),
390384
));
@@ -416,7 +410,7 @@ fn replace(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
416410
return Err(RuntimeError::simple(
417411
"InvalidArgumentRuntimeError",
418412
format!(
419-
"Expected two numbers as arguments but received {:?}",
413+
"Expected three strings as arguments but received {:?}",
420414
values
421415
),
422416
));
@@ -441,7 +435,7 @@ fn replace_first(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeE
441435
return Err(RuntimeError::simple(
442436
"InvalidArgumentRuntimeError",
443437
format!(
444-
"Expected two numbers as arguments but received {:?}",
438+
"Expected three strings as arguments but received {:?}",
445439
values
446440
),
447441
));
@@ -466,7 +460,7 @@ fn replace_last(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeEr
466460
return Err(RuntimeError::simple(
467461
"InvalidArgumentRuntimeError",
468462
format!(
469-
"Expected two numbers as arguments but received {:?}",
463+
"Expected three strings as arguments but received {:?}",
470464
values
471465
),
472466
));
@@ -500,7 +494,7 @@ fn hex(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
500494
return Err(RuntimeError::simple(
501495
"InvalidArgumentRuntimeError",
502496
format!(
503-
"Expected two numbers as arguments but received {:?}",
497+
"Expected one string as an argument but received {:?}",
504498
values
505499
),
506500
));
@@ -525,7 +519,7 @@ fn octal(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
525519
return Err(RuntimeError::simple(
526520
"InvalidArgumentRuntimeError",
527521
format!(
528-
"Expected two numbers as arguments but received {:?}",
522+
"Expected one string as an argument but received {:?}",
529523
values
530524
),
531525
));
@@ -552,7 +546,7 @@ fn index_of(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
552546
return Err(RuntimeError::simple(
553547
"InvalidArgumentRuntimeError",
554548
format!(
555-
"Expected two numbers as arguments but received {:?}",
549+
"Expected two strings as arguments but received {:?}",
556550
values
557551
),
558552
));
@@ -580,7 +574,7 @@ fn contains(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
580574
return Err(RuntimeError::simple(
581575
"InvalidArgumentRuntimeError",
582576
format!(
583-
"Expected two numbers as arguments but received {:?}",
577+
"Expected two strings as arguments but received {:?}",
584578
values
585579
),
586580
));
@@ -601,7 +595,7 @@ fn split(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
601595
return Err(RuntimeError::simple(
602596
"InvalidArgumentRuntimeError",
603597
format!(
604-
"Expected two numbers as arguments but received {:?}",
598+
"Expected two strings as arguments but received {:?}",
605599
values
606600
),
607601
));
@@ -627,7 +621,7 @@ fn reverse(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
627621
return Err(RuntimeError::simple(
628622
"InvalidArgumentRuntimeError",
629623
format!(
630-
"Expected two numbers as arguments but received {:?}",
624+
"Expected one string as an argument but received {:?}",
631625
values
632626
),
633627
));
@@ -650,7 +644,7 @@ fn starts_with(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeErr
650644
return Err(RuntimeError::simple(
651645
"InvalidArgumentRuntimeError",
652646
format!(
653-
"Expected two numbers as arguments but received {:?}",
647+
"Expected two strings as arguments but received {:?}",
654648
values
655649
),
656650
));
@@ -671,7 +665,7 @@ fn ends_with(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError
671665
return Err(RuntimeError::simple(
672666
"InvalidArgumentRuntimeError",
673667
format!(
674-
"Expected two numbers as arguments but received {:?}",
668+
"Expected two strings as arguments but received {:?}",
675669
values
676670
),
677671
));
@@ -690,7 +684,7 @@ fn to_ascii(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
690684
return Err(RuntimeError::simple(
691685
"InvalidArgumentRuntimeError",
692686
format!(
693-
"Expected two numbers as arguments but received {:?}",
687+
"Expected one string as an argument but received {:?}",
694688
values
695689
),
696690
));
@@ -710,8 +704,6 @@ fn to_ascii(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
710704
})
711705
}
712706

713-
// todo!("from_ascii")
714-
715707
fn from_ascii(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
716708
let [Value {
717709
kind: Some(Kind::ListValue(list)),
@@ -720,7 +712,7 @@ fn from_ascii(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeErro
720712
return Err(RuntimeError::simple(
721713
"InvalidArgumentRuntimeError",
722714
format!(
723-
"Expected two numbers as arguments but received {:?}",
715+
"Expected a list of numbers as an argument but received {:?}",
724716
values
725717
),
726718
));
@@ -768,7 +760,7 @@ fn encode(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
768760
return Err(RuntimeError::simple(
769761
"InvalidArgumentRuntimeError",
770762
format!(
771-
"Expected two numbers as arguments but received {:?}",
763+
"Expected two strings as arguments but received {:?}",
772764
values
773765
),
774766
));
@@ -799,7 +791,7 @@ fn decode(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError> {
799791
return Err(RuntimeError::simple(
800792
"InvalidArgumentRuntimeError",
801793
format!(
802-
"Expected two numbers as arguments but received {:?}",
794+
"Expected two strings as arguments but received {:?}",
803795
values
804796
),
805797
));
@@ -846,7 +838,7 @@ fn is_equal(values: &[Value], _ctx: &mut Context) -> Result<Value, RuntimeError>
846838
return Err(RuntimeError::simple(
847839
"InvalidArgumentRuntimeError",
848840
format!(
849-
"Expected two numbers as arguments but received {:?}",
841+
"Expected two strings as arguments but received {:?}",
850842
values
851843
),
852844
));

0 commit comments

Comments
 (0)