Skip to content

Commit e5ec2d6

Browse files
mkustermannCommit Queue
authored andcommitted
[dart2wasm] Maintain types of Errors being thrown
Strictly speaking we do not promise the specific subtypes of `Error` being thrown in the core libraries. The subtypes of `Error` are there for better messages & debugging purposes. Though some apps may rely on specific subtypes being thrown via `try { ... } on IndexError {}`. So this CL changes our errors in optimized mode to use the same `Error` subtype as in development mode. Though we do not expose details on the errors. Fields that expose details will either return `null` or throw. This makes various tests running under dart2wasm-minified mode pass. Issue #60397 Change-Id: Ie7be448b101473b18c2782457175ea163e71d5f6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435783 Reviewed-by: Ömer Ağacan <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent c111f69 commit e5ec2d6

File tree

1 file changed

+62
-26
lines changed

1 file changed

+62
-26
lines changed

sdk/lib/_internal/wasm/lib/error_utils.dart

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,20 @@ Never _throwReachabilityError([String? _message]) {
211211
throw ReachabilityError(_message);
212212
}
213213

214-
const _indexErrorWithoutDetails = _ErrorWithoutDetails(
215-
'IndexError (details omitted due to --minify)',
216-
);
217-
const _rangeErrorWithoutDetails = _ErrorWithoutDetails(
214+
const _indexErrorWithoutDetails = _IndexErrorWithoutDetails();
215+
const _rangeErrorWithoutDetails = _RangeErrorWithoutDetails(
218216
'RangeError (details omitted due to --minify)',
219217
);
220-
const _alignmentErrorWithoutDetails = _ErrorWithoutDetails(
218+
const _alignmentErrorWithoutDetails = _RangeErrorWithoutDetails(
221219
'Offset had incorrect alignment (details omitted due to --minify)',
222220
);
223-
const _negativeValueErrorWithoutDetails = _ErrorWithoutDetails(
221+
const _negativeValueErrorWithoutDetails = _RangeErrorWithoutDetails(
224222
'Value was negative (details omitted due to --minify)',
225223
);
226-
const _negativeOrZeroValueErrorWithoutDetails = _ErrorWithoutDetails(
224+
const _negativeOrZeroValueErrorWithoutDetails = _RangeErrorWithoutDetails(
227225
'Value was negative or zero (details omitted due to --minify)',
228226
);
229-
const _nullErrorWithoutDetails = _LateErrorWithoutDetails(
227+
const _nullErrorWithoutDetails = _ArgumentErrorWithoutDetails(
230228
'Value must not be null (details omitted due to --minify)',
231229
);
232230

@@ -258,44 +256,82 @@ const _reachabilityError = _LateErrorWithoutDetails(
258256
'ReachabilityError (details omitted due to --minify)',
259257
);
260258

261-
const _NoSuchMethodErrorWithoutDetails _noSuchMethodErrorWithoutDetails =
262-
_NoSuchMethodErrorWithoutDetails();
259+
const _noSuchMethodErrorWithoutDetails = _NoSuchMethodErrorWithoutDetails();
263260

264-
const _TypeErrorWithoutDetails typeErrorWithoutDetails =
265-
_TypeErrorWithoutDetails();
261+
const typeErrorWithoutDetails = _TypeErrorWithoutDetails();
266262

267263
class _ErrorWithoutDetails implements Error {
268264
final String _message;
265+
269266
const _ErrorWithoutDetails(this._message);
270267

271268
StackTrace? get stackTrace => null;
272269

273270
String toString() => _message;
274271
}
275272

276-
class _TypeErrorWithoutDetails implements TypeError {
277-
const _TypeErrorWithoutDetails();
273+
class _ArgumentErrorWithoutDetails extends _ErrorWithoutDetails
274+
implements ArgumentError {
275+
const _ArgumentErrorWithoutDetails(String message) : super(message);
278276

279-
StackTrace? get stackTrace => null;
277+
@override
278+
String? get name => null;
280279

281-
String toString() =>
282-
'Runtime type check failed (details omitted due to --minify)';
280+
@override
281+
String get message => toString();
282+
283+
@override
284+
dynamic get invalidValue => null;
283285
}
284286

285-
class _NoSuchMethodErrorWithoutDetails implements NoSuchMethodError {
286-
const _NoSuchMethodErrorWithoutDetails();
287+
class _IndexErrorWithoutDetails extends _ArgumentErrorWithoutDetails
288+
implements IndexError {
289+
const _IndexErrorWithoutDetails()
290+
: super('IndexError (details omitted due to --minify)');
287291

288-
StackTrace? get stackTrace => null;
292+
@override
293+
int get start => throw 'no details';
289294

290-
String toString() => 'NoSuchMethodError (details omitted due to --minify)';
295+
@override
296+
int get end => throw 'no details';
297+
298+
@override
299+
int get length => throw 'no details';
300+
301+
@override
302+
int get invalidValue => throw 'no details';
303+
304+
@override
305+
Object? get indexable => null;
291306
}
292307

293-
class _LateErrorWithoutDetails implements LateError {
294-
final String _message;
308+
class _RangeErrorWithoutDetails extends _ArgumentErrorWithoutDetails
309+
implements RangeError {
310+
const _RangeErrorWithoutDetails(String message) : super(message);
295311

296-
const _LateErrorWithoutDetails(this._message);
312+
@override
313+
num? get start => null;
297314

298-
StackTrace? get stackTrace => null;
315+
@override
316+
num? get end => null;
299317

300-
String toString() => _message;
318+
@override
319+
num? get invalidValue => null;
320+
}
321+
322+
class _TypeErrorWithoutDetails extends _ErrorWithoutDetails
323+
implements TypeError {
324+
const _TypeErrorWithoutDetails()
325+
: super('Runtime type check failed (details omitted due to --minify)');
326+
}
327+
328+
class _NoSuchMethodErrorWithoutDetails extends _ErrorWithoutDetails
329+
implements NoSuchMethodError {
330+
const _NoSuchMethodErrorWithoutDetails()
331+
: super('NoSuchMethodError (details omitted due to --minify)');
332+
}
333+
334+
class _LateErrorWithoutDetails extends _ErrorWithoutDetails
335+
implements LateError {
336+
const _LateErrorWithoutDetails(String message) : super(message);
301337
}

0 commit comments

Comments
 (0)