From c7b4321d08ba46f93bd6d862a04d569c4264945f Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Fri, 18 Jun 2021 16:29:55 -0700 Subject: [PATCH] Warn about a failed snapshot --- lib/src/tool_definition.dart | 23 ++++++++++++++++++----- lib/src/tool_runner.dart | 4 +++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/src/tool_definition.dart b/lib/src/tool_definition.dart index 629f8bf326..039d501e5d 100644 --- a/lib/src/tool_definition.dart +++ b/lib/src/tool_definition.dart @@ -7,6 +7,8 @@ import 'dart:async'; import 'package:analyzer/file_system/file_system.dart'; import 'package:dartdoc/src/dartdoc_options.dart'; import 'package:dartdoc/src/io_utils.dart'; +import 'package:dartdoc/src/tool_runner.dart'; +import 'package:meta/meta.dart'; import 'package:path/path.dart' as p show extension; /// Defines the attributes of a tool in the options file, corresponding to @@ -81,7 +83,8 @@ class ToolDefinition { } } - Future toolStateForArgs(List args) async { + Future toolStateForArgs(String toolName, List args, + {@required ToolErrorCallback toolErrorCallback}) async { var commandPath = args.removeAt(0); return ToolStateForArgs(commandPath, args, null); } @@ -101,14 +104,16 @@ class DartToolDefinition extends ToolDefinition { /// so that if they are executed with dart, will result in the snapshot being /// built. @override - Future toolStateForArgs(List args) async { + Future toolStateForArgs(String toolName, List args, + {@required ToolErrorCallback toolErrorCallback}) async { assert(args[0] == command.first); // Set up flags to create a new snapshot, if needed, and use the first run // as the training run. SnapshotCache.createInstance(_resourceProvider); var snapshot = SnapshotCache.instance.getSnapshot(command.first); + var snapshotFile = snapshot._snapshotFile; var snapshotPath = - _resourceProvider.pathContext.absolute(snapshot._snapshotFile.path); + _resourceProvider.pathContext.absolute(snapshotFile.path); var needsSnapshot = snapshot.needsSnapshot; if (needsSnapshot) { return ToolStateForArgs( @@ -127,8 +132,16 @@ class DartToolDefinition extends ToolDefinition { snapshot._snapshotCompleted); } else { await snapshot._snapshotValid(); - // replace the first argument with the path to the snapshot. - args[0] = snapshotPath; + if (!snapshotFile.exists) { + if (toolErrorCallback != null) { + toolErrorCallback( + 'Snapshot creation failed for $toolName tool. $snapshotPath does ' + 'not exist. Will execute tool without snapshot.'); + } + } else { + // replace the first argument with the path to the snapshot. + args[0] = snapshotPath; + } return ToolStateForArgs(_resourceProvider.resolvedExecutable, args, null); } } diff --git a/lib/src/tool_runner.dart b/lib/src/tool_runner.dart index 23e8737fc8..32d6bf128e 100644 --- a/lib/src/tool_runner.dart +++ b/lib/src/tool_runner.dart @@ -193,7 +193,9 @@ class ToolRunner { toolName, toolDefinition, envWithInput, toolErrorCallback); } - var toolStateForArgs = await toolDefinition.toolStateForArgs(argsWithInput); + var toolStateForArgs = await toolDefinition.toolStateForArgs( + toolName, argsWithInput, + toolErrorCallback: toolErrorCallback); var commandPath = toolStateForArgs.commandPath; argsWithInput = toolStateForArgs.args; var callCompleter = toolStateForArgs.onProcessComplete;