From b329ce04a83a93dccb6cf409f59edc56ca806666 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 25 Mar 2025 08:52:30 -0700 Subject: [PATCH] Improve the error message when an import cannot be resolved --- lib/src/model/prefix.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/src/model/prefix.dart b/lib/src/model/prefix.dart index 5d994e92ba..c2faaa404b 100644 --- a/lib/src/model/prefix.dart +++ b/lib/src/model/prefix.dart @@ -36,9 +36,14 @@ class Prefix extends ModelElement with HasNoPage { .firstWhere((i) => i.prefix2?.element == element); var importedLibrary = libraryImport.importedLibrary2; if (importedLibrary == null) { - throw StateError( - 'Unexpected null LibraryElement2 for imported library at ' - '${libraryImport.uri}'); + var message = 'Unexpected null LibraryElement2 for imported library at ' + '${library.element.firstFragment.source.uri}, at offset ' + '${libraryImport.importKeywordOffset}'; + var directiveUri = libraryImport.uri; + if (directiveUri is DirectiveUriWithRelativeUriString) { + message += 'for import URI: "${directiveUri.relativeUriString}"'; + } + throw StateError(message); } return importedLibrary; }