@@ -7,6 +7,8 @@ import 'dart:async';
77import 'package:analyzer/file_system/file_system.dart' ;
88import 'package:dartdoc/src/dartdoc_options.dart' ;
99import 'package:dartdoc/src/io_utils.dart' ;
10+ import 'package:dartdoc/src/tool_runner.dart' ;
11+ import 'package:meta/meta.dart' ;
1012import 'package:path/path.dart' as p show extension;
1113
1214/// Defines the attributes of a tool in the options file, corresponding to
@@ -81,7 +83,8 @@ class ToolDefinition {
8183 }
8284 }
8385
84- Future <ToolStateForArgs > toolStateForArgs (List <String > args) async {
86+ Future <ToolStateForArgs > toolStateForArgs (String toolName, List <String > args,
87+ {@required ToolErrorCallback toolErrorCallback}) async {
8588 var commandPath = args.removeAt (0 );
8689 return ToolStateForArgs (commandPath, args, null );
8790 }
@@ -101,14 +104,16 @@ class DartToolDefinition extends ToolDefinition {
101104 /// so that if they are executed with dart, will result in the snapshot being
102105 /// built.
103106 @override
104- Future <ToolStateForArgs > toolStateForArgs (List <String > args) async {
107+ Future <ToolStateForArgs > toolStateForArgs (String toolName, List <String > args,
108+ {@required ToolErrorCallback toolErrorCallback}) async {
105109 assert (args[0 ] == command.first);
106110 // Set up flags to create a new snapshot, if needed, and use the first run
107111 // as the training run.
108112 SnapshotCache .createInstance (_resourceProvider);
109113 var snapshot = SnapshotCache .instance.getSnapshot (command.first);
114+ var snapshotFile = snapshot._snapshotFile;
110115 var snapshotPath =
111- _resourceProvider.pathContext.absolute (snapshot._snapshotFile .path);
116+ _resourceProvider.pathContext.absolute (snapshotFile .path);
112117 var needsSnapshot = snapshot.needsSnapshot;
113118 if (needsSnapshot) {
114119 return ToolStateForArgs (
@@ -127,8 +132,16 @@ class DartToolDefinition extends ToolDefinition {
127132 snapshot._snapshotCompleted);
128133 } else {
129134 await snapshot._snapshotValid ();
130- // replace the first argument with the path to the snapshot.
131- args[0 ] = snapshotPath;
135+ if (! snapshotFile.exists) {
136+ if (toolErrorCallback != null ) {
137+ toolErrorCallback (
138+ 'Snapshot creation failed for $toolName tool. $snapshotPath does '
139+ 'not exist. Will execute tool without snapshot.' );
140+ }
141+ } else {
142+ // replace the first argument with the path to the snapshot.
143+ args[0 ] = snapshotPath;
144+ }
132145 return ToolStateForArgs (_resourceProvider.resolvedExecutable, args, null );
133146 }
134147 }
0 commit comments