55// See the Mustachio README at tool/mustachio/README.md for high-level
66// documentation.
77
8+ /// @docImport 'package:source_span/source_span.dart';
9+ library ;
10+
811import 'dart:collection' ;
912import 'dart:convert' show htmlEscape;
1013
1114import 'package:analyzer/file_system/file_system.dart' ;
1215import 'package:meta/meta.dart' ;
16+
1317import 'parser.dart' ;
1418
1519// TODO(devoncarew): See is we can make this synchronous.
@@ -119,7 +123,7 @@ class Template {
119123 partialTemplates: {...partialTemplates});
120124 partialTemplates[partialFile] = partialTemplate;
121125 } on FileSystemException catch (e) {
122- throw MustachioResolutionError (span.message (
126+ throw MustachioResolutionException (span.message (
123127 'FileSystemException (${e .message }) when reading partial:' ));
124128 }
125129 }
@@ -188,27 +192,26 @@ abstract class RendererBase<T extends Object?> {
188192 if (property != null ) {
189193 try {
190194 return property.renderVariable (context, property, remainingNames);
191- // ignore: avoid_catching_errors
192- } on PartialMustachioResolutionError catch (e) {
193- // The error thrown by [Property.renderVariable] does not have all of
194- // the names required for a decent error. We throw a new error here.
195- throw MustachioResolutionError (node.keySpan.message (
195+ } on PartialMustachioResolutionException catch (e) {
196+ // The exception thrown by [Property.renderVariable] does not have all
197+ // of the names required for a decent error. We throw a new error
198+ // here.
199+ throw MustachioResolutionException (node.keySpan.message (
196200 "Failed to resolve '${e .name }' on ${e .contextType } while "
197201 'resolving $remainingNames as a property chain on any types in '
198202 'the context chain: $contextChainString , after first resolving '
199203 "'$firstName ' to a property on $T " ));
200204 }
201205 }
202- // ignore: avoid_catching_errors
203- } on _MustachioResolutionErrorWithoutSpan catch (e) {
204- throw MustachioResolutionError (node.keySpan.message (e.message));
206+ } on _MustachioResolutionExceptionWithoutSpan catch (e) {
207+ throw MustachioResolutionException (node.keySpan.message (e.message));
205208 }
206209
207210 final parent = this .parent;
208211 if (parent != null ) {
209212 return parent.getFields (node);
210213 } else {
211- throw MustachioResolutionError (node.keySpan.message (
214+ throw MustachioResolutionException (node.keySpan.message (
212215 "Failed to resolve '${names .first }' as a property on any types in "
213216 'the context chain: $contextChainString ' ));
214217 }
@@ -241,7 +244,7 @@ abstract class RendererBase<T extends Object?> {
241244 if (property == null ) {
242245 final parent = this .parent;
243246 if (parent == null ) {
244- throw MustachioResolutionError (node.keySpan.message (
247+ throw MustachioResolutionException (node.keySpan.message (
245248 "Failed to resolve '$key ' as a property on any types in the "
246249 'current context' ));
247250 } else {
@@ -312,7 +315,7 @@ class SimpleRenderer extends RendererBase<Object?> {
312315 @override
313316 Property <Object >? getProperty (String key) {
314317 if (_invisibleGetters.contains (key)) {
315- throw MustachioResolutionError (_failedKeyVisibilityMessage (key));
318+ throw MustachioResolutionException (_failedKeyVisibilityMessage (key));
316319 } else {
317320 return null ;
318321 }
@@ -325,7 +328,8 @@ class SimpleRenderer extends RendererBase<Object?> {
325328 if (names.length == 1 && firstName == '.' ) {
326329 return context.toString ();
327330 } else if (_invisibleGetters.contains (firstName)) {
328- throw MustachioResolutionError (_failedKeyVisibilityMessage (firstName));
331+ throw MustachioResolutionException (
332+ _failedKeyVisibilityMessage (firstName));
329333 } else if (parent != null ) {
330334 return parent! .getFields (node);
331335 } else {
@@ -380,7 +384,7 @@ class Property<T extends Object?> {
380384 if (remainingNames.isEmpty) {
381385 return getValue (c).toString ();
382386 } else {
383- throw MustachioResolutionError (
387+ throw MustachioResolutionException (
384388 _simpleResolveErrorMessage (remainingNames, typeString));
385389 }
386390 }
@@ -391,43 +395,43 @@ class Property<T extends Object?> {
391395 "annotation's 'visibleTypes' list" ;
392396}
393397
394- /// An error indicating that a renderer failed to resolve a key.
395- class MustachioResolutionError extends Error {
398+ /// An exception indicating that a renderer failed to resolve a key.
399+ class MustachioResolutionException implements Exception {
396400 final String message;
397401
398- MustachioResolutionError (this .message);
402+ MustachioResolutionException (this .message);
399403
400404 @override
401- String toString () => 'MustachioResolutionError : $message ' ;
405+ String toString () => 'MustachioResolutionException : $message ' ;
402406}
403407
404- /// An error indicating that a renderer failed to resolve a follow-on name in a
405- /// multi-name key.
406- class PartialMustachioResolutionError extends Error {
408+ /// An exception indicating that a renderer failed to resolve a follow-on name
409+ /// in a multi-name key.
410+ class PartialMustachioResolutionException implements Exception {
407411 final String name;
408412
409413 final Type contextType;
410414
411- PartialMustachioResolutionError (this .name, this .contextType);
415+ PartialMustachioResolutionException (this .name, this .contextType);
412416}
413417
414- /// A Mustachio resolution error which is thrown in a position where the AST
415- /// node is not known.
418+ /// A Mustachio resolution exception which is thrown in a position where the
419+ /// AST node is not known.
416420///
417- /// This error should be caught and "re-thrown" as a [MustachioResolutionError]
418- /// with a message derived from a [SourceSpan] .
419- class _MustachioResolutionErrorWithoutSpan extends Error {
421+ /// This exception should be caught and "re-thrown" as a
422+ /// [MustachioResolutionException] with a message derived from a [SourceSpan] .
423+ class _MustachioResolutionExceptionWithoutSpan implements Exception {
420424 final String message;
421425
422- _MustachioResolutionErrorWithoutSpan (this .message);
426+ _MustachioResolutionExceptionWithoutSpan (this .message);
423427}
424428
425429extension MapExtensions <T > on Map <String , Property <T >> {
426430 Property <T > getValue (String name) {
427431 if (containsKey (name)) {
428432 return this [name]! ;
429433 } else {
430- throw PartialMustachioResolutionError (name, T );
434+ throw PartialMustachioResolutionException (name, T );
431435 }
432436 }
433437}
0 commit comments