Implement error-specific exit codes

This commit is contained in:
2024-08-11 20:21:01 -04:00
parent 06b9527a33
commit ed9c4e91ff
18 changed files with 102 additions and 88 deletions
+7 -7
View File
@@ -26,7 +26,7 @@ func genDeviceIDList() *[]fs.DirEntry {
deviceIDList, err := os.ReadDir(core.ConfigDir + core.PathSeparator + "devices")
if err != nil {
fmt.Println(core.AnsiError + "Failed to read the devices directory: " + err.Error() + core.AnsiReset)
os.Exit(1)
os.Exit(101)
}
return &deviceIDList
}
@@ -52,7 +52,7 @@ func ShearLocal(targetLocationIncomplete, clientDeviceID string) string {
if err != nil {
// do not print error as there is currently no way of seeing server-side errors
// failure to add the target to the deletions list will exit the program and result in a client re-uploading the target (non-critical)
os.Exit(1)
os.Exit(102)
}
}
}
@@ -66,7 +66,7 @@ func ShearLocal(targetLocationIncomplete, clientDeviceID string) string {
err := os.RemoveAll(targetLocationComplete)
if err != nil {
fmt.Println(core.AnsiError + "Failed to remove local target: " + err.Error() + core.AnsiReset)
os.Exit(1)
os.Exit(102)
}
if !onServer && len(*deviceIDList) > 0 { // return the device ID if running on the client and a device ID exists (online mode)
@@ -92,13 +92,13 @@ func RenameLocal(oldLocationIncomplete, newLocationIncomplete string, verifyOldL
_, isAccessible := core.TargetIsFile(newLocation, false, 0)
if isAccessible {
fmt.Println(core.AnsiError + "\"" + newLocation + "\" already exists" + core.AnsiReset)
os.Exit(1)
os.Exit(106)
}
// rename oldLocation to newLocation
err := os.Rename(oldLocation, newLocation)
if err != nil {
fmt.Println(core.AnsiError + "Failed to rename - does the target containing directory exist?" + core.AnsiReset)
fmt.Println(core.AnsiError + "Failed to rename - Does the target containing directory exist?" + core.AnsiReset)
}
// do not exit program, as this function is used as part of RenameRemoteFromClient
@@ -113,10 +113,10 @@ func AddFolderLocal(targetLocationIncomplete string) {
if err != nil {
if os.IsExist(err) {
fmt.Println(core.AnsiError + "Directory already exists" + core.AnsiReset)
os.Exit(1)
os.Exit(106)
} else {
fmt.Println(core.AnsiError + "Failed to create directory: " + err.Error() + core.AnsiReset)
os.Exit(1)
os.Exit(102)
}
}