readTicketJson function

TicketJson? readTicketJson(
  1. Directory ticketDir
)

Reads <ticketDir>/ticket.json, or returns null when the file is missing or malformed.

A gg version mismatch is not swallowed: TicketJson.fromJsonString throws so the user learns that their gg is too old, instead of silently getting an incomplete ticket.

Implementation

TicketJson? readTicketJson(Directory ticketDir) {
  final file = File(path.join(ticketDir.path, ticketJsonFileName));
  if (!file.existsSync()) {
    return null;
  }
  try {
    return TicketJson.fromJsonString(file.readAsStringSync());
  } on FormatException {
    // A hand-edited / truncated ticket.json must not crash the caller.
    return null;
  }
}