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

View file

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

View file

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