Skip to content

Commit

Permalink
Always non-nullable DartdocResult. (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Dec 21, 2023
1 parent f1b8347 commit 937a14a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
53 changes: 29 additions & 24 deletions lib/src/package_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'repository/check_repository.dart';
import 'screenshots.dart';
import 'sdk_env.dart';
import 'tag/license_tags.dart';
import 'utils.dart' show listFocusDirs, PanaProcessResult;
import 'utils.dart' show listFocusDirs;

/// Shared (intermediate) results between different packages or versions.
/// External systems that may be independent of the archive content may be
Expand Down Expand Up @@ -228,10 +228,10 @@ class PackageContext {
return LicenseTags.fromLicenses(await licenses);
}();

late final Future<DartdocResult?> dartdocResult = () async {
late final Future<DartdocResult> dartdocResult = () async {
final dartdocOutputDir = options.dartdocOutputDir;
if (dartdocOutputDir == null) {
return null;
return DartdocResult.skipped();
}
if (await resolveDependencies()) {
final timeout = options.dartdocTimeout ?? const Duration(minutes: 5);
Expand All @@ -245,52 +245,57 @@ class PackageContext {
usesFlutter: usesFlutter,
);
if (pr.exitCode == 15) {
return DartdocResult(
errorReason: '`dartdoc` could not complete in $timeout.');
return DartdocResult.error(
'`dartdoc` could not complete in $timeout.');
}
if (pr.exitCode != 0) {
return DartdocResult(errorReason: pr.asTrimmedOutput);
return DartdocResult.error(pr.asTrimmedOutput);
}

final hasIndexHtml =
await File(p.join(dartdocOutputDir, 'index.html')).exists();
final hasIndexJson =
await File(p.join(dartdocOutputDir, 'index.json')).exists();
return DartdocResult(
processResult: pr, hasOutputFiles: hasIndexHtml && hasIndexJson);
if (!hasIndexHtml || !hasIndexJson) {
return DartdocResult.error(
'`dartdoc` did not create expected output files.');
}
return DartdocResult.success();
} catch (e, st) {
log.severe('Could not run dartdoc.', e, st);
return DartdocResult(errorReason: 'Could not run `dartdoc`: $e');
return DartdocResult.error('Could not run `dartdoc`: $e');
}
} else {
return DartdocResult(
errorReason: 'Dependency resultion failed, unable to run `dartdoc`.');
return DartdocResult.error(
'Dependency resultion failed, unable to run `dartdoc`.');
}
}();

late final dartdocPubData = () async {
final dr = await dartdocResult;
if (dr == null || !dr.wasSuccessful) {
if (dr.wasSuccessful) {
return await generateAndSavePubDataJson(options.dartdocOutputDir!);
} else {
return null;
}
return await generateAndSavePubDataJson(options.dartdocOutputDir!);
}();
}

class DartdocResult {
final PanaProcessResult? processResult;
final bool wasRunning;
final String? errorReason;
final bool hasOutputFiles;

DartdocResult({
this.processResult,
DartdocResult.error(
this.errorReason,
this.hasOutputFiles = false,
});
) : wasRunning = true;

DartdocResult.skipped()
: wasRunning = false,
errorReason = null;

DartdocResult.success()
: wasRunning = true,
errorReason = null;

bool get wasSuccessful =>
processResult != null &&
processResult!.exitCode == 0 &&
errorReason == null &&
hasOutputFiles;
bool get wasSuccessful => wasRunning && errorReason == null;
}
2 changes: 1 addition & 1 deletion lib/src/report/documentation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Future<ReportSection> hasDocumentation(PackageContext context) async {
Subsection? documentation;
if (dartdocPubData != null) {
documentation = await createDocumentationCoverageSection(dartdocPubData);
} else if (dartdocResult != null) {
} else if (dartdocResult.wasRunning) {
documentation = dartdocFailedSubsection(
dartdocResult.errorReason ?? 'Running or processing dartdoc failed.');
}
Expand Down

0 comments on commit 937a14a

Please sign in to comment.