mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-01 22:57:25 -04:00
Assign error-specific exit codes to constants
This commit is contained in:
@@ -19,20 +19,20 @@ func TargetIsFile(targetLocation string, errorOnFail bool, failCondition uint8)
|
||||
if err != nil {
|
||||
if errorOnFail {
|
||||
fmt.Println(AnsiError + "Failed to access \"" + targetLocation + "\" - Ensure it exists and has the correct permissions" + AnsiReset)
|
||||
os.Exit(105)
|
||||
os.Exit(ErrorTargetNotFound)
|
||||
}
|
||||
return false, false
|
||||
}
|
||||
if targetInfo.IsDir() {
|
||||
if errorOnFail && failCondition == 2 {
|
||||
fmt.Println(AnsiError + "\"" + targetLocation + "\" is a directory" + AnsiReset)
|
||||
os.Exit(107)
|
||||
os.Exit(ErrorTargetWrongType)
|
||||
}
|
||||
return false, true
|
||||
} else {
|
||||
if errorOnFail && failCondition == 1 {
|
||||
fmt.Println(AnsiError + "\"" + targetLocation + "\" is a file" + AnsiReset)
|
||||
os.Exit(107)
|
||||
os.Exit(ErrorTargetWrongType)
|
||||
}
|
||||
return true, true
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func WriteEntry(targetLocation string, entryData []string, verifyEntryDoesNotExi
|
||||
_, isAccessible := TargetIsFile(targetLocation, false, 0)
|
||||
if isAccessible {
|
||||
fmt.Println(AnsiError + "Target location already exists" + AnsiReset)
|
||||
os.Exit(106)
|
||||
os.Exit(ErrorTargetExists)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func WriteEntry(targetLocation string, entryData []string, verifyEntryDoesNotExi
|
||||
err := os.WriteFile(targetLocation, encryptedBytes, 0600)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError+"Failed to write to file:", err.Error()+AnsiReset)
|
||||
os.Exit(102)
|
||||
os.Exit(ErrorWrite)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ func writeToStdin(cmd *exec.Cmd, input string) {
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError+"Failed to access stdin for system command:", err.Error()+AnsiReset)
|
||||
os.Exit(111)
|
||||
os.Exit(ErrorOther)
|
||||
}
|
||||
|
||||
go func() {
|
||||
@@ -77,7 +77,7 @@ func CreateTempFile() *os.File {
|
||||
tempFile, err := os.CreateTemp("", "*.markdown")
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError+"Failed to create temporary file:", err.Error()+AnsiReset)
|
||||
os.Exit(102)
|
||||
os.Exit(ErrorWrite)
|
||||
}
|
||||
return tempFile
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user