parse method

Schema parse(
  1. String path
)

Reads and deserialises the JSON schema file at path into a Schema.

Calls CommandHelper.error (which exits in production) when the file is missing or contains invalid JSON, so the user receives a clear message rather than a raw stack trace.

Implementation

Schema parse(String path) {
  final file = File(path);
  if (!file.existsSync()) {
    _commandHelper.error('Schema file not found: $path');
    // error() calls exit(1) in production; rethrow path for test doubles.
    throw StateError('Schema file not found: $path');
  }

  try {
    final json = jsonDecode(file.readAsStringSync());
    return Schema.fromJson(json as Map<String, dynamic>);
  } on FormatException catch (e) {
    _commandHelper.error('Invalid JSON in schema file "$path": ${e.message}');
    throw StateError('Invalid JSON in schema file "$path": ${e.message}');
  }
}