Better error when path dependency has no pubspec.yaml (#3787)

diff --git a/lib/src/source/path.dart b/lib/src/source/path.dart
index aa94dc8..83358ea 100644
--- a/lib/src/source/path.dart
+++ b/lib/src/source/path.dart
@@ -14,7 +14,6 @@
 import '../pubspec.dart';
 import '../source.dart';
 import '../system_cache.dart';
-import '../utils.dart';
 
 /// A package [Source] that gets packages from a given local file path.
 class PathSource extends Source {
@@ -191,16 +190,27 @@
   /// normalized path to the package.
   ///
   /// It must be a map, with a "path" key containing a path that points to an
-  /// existing directory. Throws an [ApplicationException] if the path is
-  /// invalid.
+  /// existing directory. Throws an [PackageNotFoundException] if the path is
+  /// invalid or a pubspec.yaml file doesn't exist at the location.
   String _validatePath(String name, PathDescription description) {
     final dir = description.path;
 
-    if (dirExists(dir)) return dir;
-
+    if (dirExists(dir)) {
+      final pubspecPath = p.join(dir, 'pubspec.yaml');
+      if (!fileExists(pubspecPath)) {
+        throw PackageNotFoundException(
+          'No pubspec.yaml found for package $name in $dir.',
+          innerError: FileException('$pubspecPath doesn\'t exist', pubspecPath),
+        );
+      }
+      return dir;
+    }
     if (fileExists(dir)) {
-      fail('Path dependency for package $name must refer to a directory, '
-          'not a file. Was "$dir".');
+      throw PackageNotFoundException(
+        'Path dependency for package $name must refer to a directory, '
+        'not a file. Was "$dir".',
+        innerError: FileException('$dir is not a directory.', dir),
+      );
     }
     throw PackageNotFoundException(
       'could not find package $name at "${description.format()}"',
diff --git a/test/get/path/no_pubspec_test.dart b/test/get/path/no_pubspec_test.dart
index 769f67b..5962ff9 100644
--- a/test/get/path/no_pubspec_test.dart
+++ b/test/get/path/no_pubspec_test.dart
@@ -24,8 +24,8 @@
     ]).create();
 
     await pubGet(
-      error: RegExp(r'Could not find a file named "pubspec.yaml" '
-          r'in "[^\n]*"\.'),
+      error: 'Because myapp depends on foo from path which doesn\'t exist '
+          '(No pubspec.yaml found for package foo in $fooPath.), version solving failed.',
       exitCode: exit_codes.NO_INPUT,
     );
   });
diff --git a/test/get/path/nonexistent_dir_test.dart b/test/get/path/nonexistent_dir_test.dart
index c17d421..d914dfd 100644
--- a/test/get/path/nonexistent_dir_test.dart
+++ b/test/get/path/nonexistent_dir_test.dart
@@ -22,11 +22,8 @@
     ]).create();
 
     await pubGet(
-      error: allOf([
-        contains("Because myapp depends on foo from path which doesn't exist "
-            '(could not find package foo at'),
-        contains('bad_path"), version solving failed.')
-      ]),
+      error: 'Because myapp depends on foo from path which doesn\'t exist '
+          '(could not find package foo at "$badPath"), version solving failed.',
       exitCode: exit_codes.NO_INPUT,
     );
   });
diff --git a/test/get/path/path_is_file_test.dart b/test/get/path/path_is_file_test.dart
index 579caae..9853648 100644
--- a/test/get/path/path_is_file_test.dart
+++ b/test/get/path/path_is_file_test.dart
@@ -3,6 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'package:path/path.dart' as path;
+import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
 
 import '../../descriptor.dart' as d;
@@ -25,8 +26,9 @@
     ]).create();
 
     await pubGet(
-      error: 'Path dependency for package foo must refer to a '
-          'directory, not a file. Was "$dummyPath".',
+      error: 'Because myapp depends on foo from path which doesn\'t exist '
+          '(Path dependency for package foo must refer to a directory, not a file. Was "$dummyPath".), version solving failed.',
+      exitCode: exit_codes.NO_INPUT,
     );
   });
 }