renderDoctorJson function
String
renderDoctorJson(
- DoctorReport report,
- List<
String> blocking, { - CompatibilityResult? compatibility,
Renders the DoctorReport in JSON format wrapped in the standard envelope.
Binds: R-009, FR-007, FR-009, contracts/json-schemas.md.
Implementation
String renderDoctorJson(
DoctorReport report,
List<String> blocking, {
CompatibilityResult? compatibility,
}) {
final hasBlocking = blocking.isNotEmpty;
final resultJson = {
'flutterStartVersion': report.flutterStartVersion.value,
'flutter':
report.flutterExecutable.observed || report.flutterVersion.observed
? {
'observed': true,
'executable': report.flutterExecutable.value,
'version': report.flutterVersion.value,
}
: {'observed': false, 'executable': null, 'version': null},
'dart': report.dartExecutable.observed || report.dartVersion.observed
? {
'observed': true,
'executable': report.dartExecutable.value,
'version': report.dartVersion.value,
}
: {'observed': false, 'executable': null, 'version': null},
'git': report.gitAvailable.observed
? {'observed': true, 'available': report.gitAvailable.value}
: {'observed': false, 'available': null},
'hostOs': report.hostOs.value,
'caseSensitiveFilesystem': report.caseSensitivity.value,
'stagingAccess': report.stagingAccess.observed
? (report.stagingAccess.value == true ? 'ok' : 'failed')
: null,
'tempAccess': report.tempAccess.observed
? (report.tempAccess.value == true ? 'ok' : 'failed')
: null,
'recipeCompatibility': report.recipeCompatibility.observed
? (report.recipeCompatibility.value == true ? 'ok' : 'failed')
: null,
'engineCompatibility': report.engineCompatibility.observed
? (report.engineCompatibility.value == true ? 'ok' : 'failed')
: null,
'rendererVersion': report.rendererVersionCompatibility.observed
? {
'mason': '0.1.2',
'compatible': report.rendererVersionCompatibility.value,
}
: {'observed': false},
'windowsLongPath': report.windowsLongPathStatus.observed
? report.windowsLongPathStatus.value
: null,
'network': report.networkReachability.observed
? {
'observed': true,
'packageHostReachable': report.networkReachability.value,
}
: {'observed': false},
'packageCache': report.packageCacheClassification.observed
? {
'state': report.packageCacheClassification.value?.name,
'missing': report.packageCacheMissing.value ?? [],
}
: {'observed': false},
'provisional': report.provisionalNotes.value ?? [],
'blocking': blocking,
};
return renderEnvelope(
command: 'doctor',
ok: !hasBlocking,
exitCode: hasBlocking
? ExitReporter.environmentPreflightFailure
: ExitReporter.success,
result: resultJson,
warnings: [
for (final finding
in compatibility?.warnings ?? const <CompatibilityFinding>[])
{'code': finding.code, 'message': finding.message},
],
error: hasBlocking
? {
'code': 'ENVIRONMENT_PREFLIGHT_FAILURE',
'exitCode': ExitReporter.environmentPreflightFailure,
'message':
'Environment preflight check failed: ${blocking.join(", ")}',
'cause': {
'kind': 'environmentPreflightFailure',
'blockingConditions': blocking,
},
'missingDecisions': [],
}
: null,
encoder: const JsonEncoder.withIndent(' '),
);
}