Skip to content

Commit d4f29bc

Browse files
committed
feat: updates the exception class name and changes its message type to
Map
1 parent cb027a1 commit d4f29bc

File tree

14 files changed

+109
-94
lines changed

14 files changed

+109
-94
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.7.1
2+
3+
- Rename `ValidationException` class to `VineValidationException` to prevent collision with `ValidationException` class from another packages
4+
- Change `ValidationException.message` from `String` to `Map<String, dynamic>`
5+
16
## 1.7.0
27

38
- Rename `Field` class to `VineField`

lib/src/contracts/vine.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abstract interface class VineErrorReporter {
1010

1111
void report(String rule, List<String> keys, String message);
1212

13-
Exception createError(Object message);
13+
Exception createError(Map<String, dynamic> message);
1414

1515
void clear();
1616
}

lib/src/error_reporter.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:convert';
2-
31
import 'package:vine/src/contracts/vine.dart';
42
import 'package:vine/src/exceptions/validation_exception.dart';
53
import 'package:vine/src/mapped_errors.dart';
@@ -42,8 +40,8 @@ class SimpleErrorReporter implements VineErrorReporter {
4240
}
4341

4442
@override
45-
Exception createError(Object message) {
46-
return ValidationException(json.encode(message));
43+
Exception createError(Map<String, dynamic> message) {
44+
return VineValidationException(message);
4745
}
4846

4947
@override
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
class ValidationException implements Exception {
1+
import 'dart:convert';
2+
3+
class VineValidationException implements Exception {
24
String code = 'E_VALIDATION_ERROR';
35
final statusCode = 422;
46

5-
final String message;
6-
ValidationException(this.message);
7-
7+
final Map<String, dynamic> message;
8+
VineValidationException(this.message);
89

910
@override
10-
String toString() => '[$code]: $message';
11+
String toString() => '[$code]: ${json.encode(message)}';
1112
}

lib/src/vine.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ final class Validator implements VineValidatorContract {
132132

133133
VineSchema get schema => _schema.clone();
134134

135-
(ValidationException?, T?) tryValidate<T>(dynamic data) {
135+
(VineValidationException?, T?) tryValidate<T>(dynamic data) {
136136
try {
137137
final result = validate(data);
138138
return (null, result);
139-
} on ValidationException catch (exception) {
139+
} on VineValidationException catch (exception) {
140140
return (exception, null);
141141
}
142142
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: vine
22
description: Vine is a robust, typed validation library for Dart/Flutter, designed to simplify and secure data management in applications
3-
version: 1.7.0
3+
version: 1.7.1
44
repository: https://github.com/LeadcodeDev/vine
55

66
platforms:

test/rules/array_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ void main() {
9595
() => validator.validate({
9696
'value': ['foo', 1, true]
9797
}),
98-
throwsA(isA<ValidationException>()));
98+
throwsA(isA<VineValidationException>()));
9999
});
100100

101101
test('is invalid when value is not array', () {
102102
final validator =
103103
vine.compile(vine.object({'value': vine.array(vine.string())}));
104104

105105
expect(() => validator.validate({'value': 'foo'}),
106-
throwsA(isA<ValidationException>()));
106+
throwsA(isA<VineValidationException>()));
107107
});
108108
});
109109

@@ -138,7 +138,7 @@ void main() {
138138
() => validator.validate({
139139
'array': ['foo']
140140
}),
141-
throwsA(isA<ValidationException>()));
141+
throwsA(isA<VineValidationException>()));
142142
});
143143
});
144144
}

test/rules/boolean_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void main() {
5151
final validator = vine.compile(vine.object({'value': vine.boolean()}));
5252

5353
expect(() => validator.validate({'value': 'foo'}),
54-
throwsA(isA<ValidationException>()));
54+
throwsA(isA<VineValidationException>()));
5555
});
5656
});
5757
}

test/rules/date_test.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ void main() {
5151
'date': vine.date(),
5252
}));
5353

54-
expect(
55-
() => validator.validate(payload), throwsA(isA<ValidationException>()));
54+
expect(() => validator.validate(payload),
55+
throwsA(isA<VineValidationException>()));
5656
});
5757

5858
test('should be valid when value is between dates', () {
@@ -70,8 +70,8 @@ void main() {
7070
'date': vine.date().between(DateTime(2022), DateTime(2023)),
7171
}));
7272

73-
expect(
74-
() => validator.validate(payload), throwsA(isA<ValidationException>()));
73+
expect(() => validator.validate(payload),
74+
throwsA(isA<VineValidationException>()));
7575
});
7676

7777
group('Date rules', () {
@@ -97,7 +97,7 @@ void main() {
9797
}));
9898

9999
expect(() => validator.validate(payload),
100-
throwsA(isA<ValidationException>()));
100+
throwsA(isA<VineValidationException>()));
101101
});
102102

103103
test('should be valid when value is after the target date', () {
@@ -122,7 +122,7 @@ void main() {
122122
}));
123123

124124
expect(() => validator.validate(payload),
125-
throwsA(isA<ValidationException>()));
125+
throwsA(isA<VineValidationException>()));
126126
});
127127

128128
test('should be valid when value is before the target field', () {
@@ -150,7 +150,7 @@ void main() {
150150
}));
151151

152152
expect(() => validator.validate(payload),
153-
throwsA(isA<ValidationException>()));
153+
throwsA(isA<VineValidationException>()));
154154
});
155155

156156
test('should be valid when value is after the target field', () {
@@ -178,7 +178,7 @@ void main() {
178178
}));
179179

180180
expect(() => validator.validate(payload),
181-
throwsA(isA<ValidationException>()));
181+
throwsA(isA<VineValidationException>()));
182182
});
183183

184184
test('should be valid when value is between date fields', () {
@@ -210,7 +210,7 @@ void main() {
210210
}));
211211

212212
expect(() => validator.validate(payload),
213-
throwsA(isA<ValidationException>()));
213+
throwsA(isA<VineValidationException>()));
214214
});
215215

216216
test(
@@ -227,7 +227,7 @@ void main() {
227227
}));
228228

229229
expect(() => validator.validate(payload),
230-
throwsA(isA<ValidationException>()));
230+
throwsA(isA<VineValidationException>()));
231231
});
232232

233233
test(
@@ -245,7 +245,7 @@ void main() {
245245
}));
246246

247247
expect(() => validator.validate(payload),
248-
throwsA(isA<ValidationException>()));
248+
throwsA(isA<VineValidationException>()));
249249
});
250250

251251
test('should be valid when value has attempted value after transformation',

test/rules/enum_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void main() {
3232
vine.compile(vine.object({'value': vine.enumerate(MyEnum.values)}));
3333

3434
expect(() => validator.validate({'value': 'value4'}),
35-
throwsA(isA<ValidationException>()));
35+
throwsA(isA<VineValidationException>()));
3636
});
3737

3838
test('is valid when value is nullable', () {

0 commit comments

Comments
 (0)