Skip to content

Commit bacf593

Browse files
authored
Warn about a failed snapshot (dart-lang#2731)
1 parent be86d03 commit bacf593

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

lib/src/tool_definition.dart

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'dart:async';
77
import 'package:analyzer/file_system/file_system.dart';
88
import 'package:dartdoc/src/dartdoc_options.dart';
99
import 'package:dartdoc/src/io_utils.dart';
10+
import 'package:dartdoc/src/tool_runner.dart';
11+
import 'package:meta/meta.dart';
1012
import '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
}

lib/src/tool_runner.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ class ToolRunner {
191191
toolName, toolDefinition, envWithInput, toolErrorCallback);
192192
}
193193

194-
var toolStateForArgs = await toolDefinition.toolStateForArgs(argsWithInput);
194+
var toolStateForArgs = await toolDefinition.toolStateForArgs(
195+
toolName, argsWithInput,
196+
toolErrorCallback: toolErrorCallback);
195197
var commandPath = toolStateForArgs.commandPath;
196198
argsWithInput = toolStateForArgs.args;
197199
var callCompleter = toolStateForArgs.onProcessComplete;

0 commit comments

Comments
 (0)