Skip to content

Warn about a failed snapshot #2731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/src/tool_definition.dart
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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