Skip to content

Commit

Permalink
Warn about a failed snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Jun 18, 2021
1 parent 3cf7c63 commit c7b4321
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
23 changes: 18 additions & 5 deletions lib/src/tool_definition.dart
Expand Up @@ -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
Expand Down Expand Up @@ -81,7 +83,8 @@ class ToolDefinition {
}
}

Future<ToolStateForArgs> toolStateForArgs(List<String> args) async {
Future<ToolStateForArgs> toolStateForArgs(String toolName, List<String> args,
{@required ToolErrorCallback toolErrorCallback}) async {
var commandPath = args.removeAt(0);
return ToolStateForArgs(commandPath, args, null);
}
Expand All @@ -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> toolStateForArgs(List<String> args) async {
Future<ToolStateForArgs> toolStateForArgs(String toolName, List<String> 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(
Expand All @@ -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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/tool_runner.dart
Expand Up @@ -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;
Expand Down

0 comments on commit c7b4321

Please sign in to comment.