From b68b2a8931fe36840a181df2bfa49ab4536d5d47 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 13 Aug 2024 17:36:15 -0400 Subject: [PATCH] Implement error-specific exit codes defined by libmutton --- README.md | 4 ++-- docs/man | 26 ++++++++++++++++++++++++-- src/cli/add.go | 2 +- src/cli/edit.go | 2 +- src/cli/init.go | 4 ++-- src/cli/utilitiesMisc.go | 2 +- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0626625..9a286c1 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ After installing, please review the [usage guide](https://github.com/rwinkhart/M - [ ] libmutton v0.2.1 - [ ] Only run getSSHClient once to prevent being asked for keyfile password multiple times - [ ] Ensure all config files and entry files are created with 0600 permissions - - [ ] Add fail-specific error codes - - [ ] Document in man page + - [x] Add fail-specific error codes + - [x] Document in man page - [x] Split into separate repos 1. libmutton: backend package (rename to core), sync package, libmuttonserver 3. MUTN: cli package diff --git a/docs/man b/docs/man index c11f8aa..9c013db 100644 --- a/docs/man +++ b/docs/man @@ -144,8 +144,30 @@ Once this has been done, you may proceed with the client setup: ...and then restart your shell. -.SH EXIT CODES -TBD +.SH EXIT CODES (defined by libmutton) +0: no error + +101: read error + +102: write error + +103: sync process error + +104: server connection error + +105: target not found + +106: target already exists + +107: target wrong type (file/directory) + +108: decryption error + +109: encryption error + +110: clipboard error + +111: other error .SH AUTHOR Randall Winkhart (https://github.com/rwinkhart) diff --git a/src/cli/add.go b/src/cli/add.go index 84f8937..88b8d99 100644 --- a/src/cli/add.go +++ b/src/cli/add.go @@ -15,7 +15,7 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) { _, isAccessible := core.TargetIsFile(targetLocation, false, 0) if isAccessible { fmt.Println(core.AnsiError + "Target location already exists" + core.AnsiReset) - os.Exit(1) + os.Exit(106) } // ensure target containing directory exists and is a directory (not a file) diff --git a/src/cli/edit.go b/src/cli/edit.go index d2cf8e8..98ef5c4 100644 --- a/src/cli/edit.go +++ b/src/cli/edit.go @@ -45,7 +45,7 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) { editedNote, noteEdited := editNote(noteData) if !noteEdited { // exit early if the note was not edited fmt.Println(core.AnsiError + "Entry is unchanged" + core.AnsiReset) - os.Exit(1) + os.Exit(0) } unencryptedEntry = append(nonNoteData, editedNote...) } diff --git a/src/cli/init.go b/src/cli/init.go index 181bcdb..7d8f996 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -22,7 +22,7 @@ func TempInitCli() { gpgIDInt := inputMenuGen("Select GPG key:", uidSlice) if gpgIDInt == 0 { fmt.Println(core.AnsiError + "No GPG keys found - please generate one" + core.AnsiReset) - os.Exit(1) + os.Exit(105) } gpgID = uidSlice[gpgIDInt-1] } @@ -47,7 +47,7 @@ func TempInitCli() { sshKey = cmp.Or(expandPathWithHome(input("SSH private identity file path (falls back to \""+fallbackSSHKey+"\"):")), fallbackSSHKey) sshKeyIsFile, _ = core.TargetIsFile(sshKey, false, 0) if !sshKeyIsFile { - fmt.Println(core.AnsiError + "SSH identity file not found: " + sshKey + core.AnsiReset) + fmt.Println(core.AnsiError+"SSH identity file not found:", sshKey+core.AnsiReset) } } diff --git a/src/cli/utilitiesMisc.go b/src/cli/utilitiesMisc.go index 72a08a4..b11cd31 100644 --- a/src/cli/utilitiesMisc.go +++ b/src/cli/utilitiesMisc.go @@ -74,7 +74,7 @@ func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets EntryReader(unencryptedEntry, hideSecrets, true) } else { fmt.Println(core.AnsiError + "No data supplied for entry" + core.AnsiReset) - os.Exit(1) + os.Exit(105) } }