refactor: remove unnecessary try-catch

This commit is contained in:
Aleksey Kulikov 2021-08-05 19:58:34 +03:00
parent 9190ed2e0f
commit 4f851bc2e5
3 changed files with 22 additions and 84 deletions

View file

@ -22,21 +22,13 @@ class Config {
libgit2.git_libgit2_init();
if (path == null) {
try {
_configPointer = bindings.openDefault().value;
} catch (e) {
rethrow;
}
} else {
try {
if (File(path!).existsSync()) {
_configPointer = bindings.open(path!).value;
} else {
throw Exception('File not found');
}
} catch (e) {
rethrow;
}
}
}
@ -104,16 +96,11 @@ class Config {
/// Returns the value of config [variable].
String getValue(String variable) {
try {
return bindings.getValue(_configPointer, variable);
} catch (e) {
rethrow;
}
}
/// Sets the [value] of config [variable].
void setValue(String variable, dynamic value) {
try {
if (value.runtimeType == bool) {
bindings.setBool(_configPointer, variable, value);
} else if (value.runtimeType == int) {
@ -121,9 +108,6 @@ class Config {
} else {
bindings.setString(_configPointer, variable, value);
}
} catch (e) {
rethrow;
}
}
/// Deletes [variable] from the config file with the highest level
@ -131,11 +115,7 @@ class Config {
///
/// Throws a [LibGit2Error] if error occured.
void deleteEntry(String variable) {
try {
bindings.deleteEntry(_configPointer, variable);
} catch (e) {
rethrow;
}
}
/// Returns list of values for multivar [variable]

View file

@ -17,11 +17,7 @@ class Oid {
Oid.fromSHA(String sha) {
libgit2.git_libgit2_init();
try {
_oidPointer = bindings.fromSHA(sha);
} catch (e) {
rethrow;
}
}
/// Initializes a new instance of [Oid] class from provided
@ -39,13 +35,7 @@ class Oid {
Pointer<git_oid> get pointer => _oidPointer;
/// Returns hexadecimal SHA-1 string.
String get sha {
try {
return bindings.toSHA(_oidPointer);
} catch (e) {
rethrow;
}
}
String get sha => bindings.toSHA(_oidPointer);
@override
bool operator ==(other) {

View file

@ -20,11 +20,7 @@ class Repository {
Repository.open(String path) {
libgit2.git_libgit2_init();
try {
_repoPointer = bindings.open(path);
} catch (e) {
rethrow;
}
}
/// Pointer to memory address for allocated repository object.
@ -58,11 +54,7 @@ class Repository {
///
/// Throws a [LibGit2Error] if error occured.
void setNamespace(String? namespace) {
try {
bindings.setNamespace(_repoPointer, namespace);
} catch (e) {
rethrow;
}
}
/// Checks whether this repository is a bare repository or not.
@ -82,11 +74,7 @@ class Repository {
///
/// Throws a [LibGit2Error] if error occured.
bool get isHeadDetached {
try {
return bindings.isHeadDetached(_repoPointer);
} catch (e) {
rethrow;
}
}
/// Creates a new reference.
@ -186,11 +174,7 @@ class Repository {
///
/// Throws a [LibGit2Error] if error occured.
void setHead(String reference) {
try {
bindings.setHead(_repoPointer, reference);
} catch (e) {
rethrow;
}
}
/// Checks if the current branch is unborn.
@ -200,11 +184,7 @@ class Repository {
///
/// Throws a [LibGit2Error] if error occured.
bool get isBranchUnborn {
try {
return bindings.isBranchUnborn(_repoPointer);
} catch (e) {
rethrow;
}
}
/// Sets the identity to be used for writing reflogs.
@ -235,13 +215,7 @@ class Repository {
/// Don't forget to remove the file with [removeMessage] after you create the commit.
///
/// Throws a [LibGit2Error] if error occured.
String get message {
try {
return bindings.message(_repoPointer);
} catch (e) {
rethrow;
}
}
String get message => bindings.message(_repoPointer);
/// Removes git's prepared message.
void removeMessage() => bindings.removeMessage(_repoPointer);
@ -255,13 +229,7 @@ class Repository {
/// merge, revert, cherry-pick, etc. For example: MERGE_HEAD, MERGE_MSG, etc.
///
/// Throws a [LibGit2Error] if error occured.
void stateCleanup() {
try {
bindings.stateCleanup(_repoPointer);
} catch (e) {
rethrow;
}
}
void stateCleanup() => bindings.stateCleanup(_repoPointer);
/// Returns the path of the working directory for this repository.
///