Commit 64eb8e81 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Error message fidelity

Get error messages to better align with the FORTRAN version.
Closes #6.
parent 468f6492
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ func ActionCreate(cmd *dclish.Command) error {

	if cmd.Flags["/OWNER"].Value != "" {
		if this.User.Admin == 0 {
			return errors.New("must be admin to specify /OWNER")
			return errors.New("/OWNER requires privileges")
		}
		options.Owner = cmd.Flags["/OWNER"].Value
	} else {
@@ -187,7 +187,7 @@ func ActionSelect(cmd *dclish.Command) error {
// This is based on `MODIFY_FOLDER` in bulletin1.for.
func ActionModify(cmd *dclish.Command) error {
	if this.User.Login != this.Folder.Owner && this.User.Admin == 0 {
		return errors.New("must be folder owner or admin to modify the folder")
		return errors.New("no privileges to modify folder")
	}
	var err error
	description := this.Folder.Description
@@ -230,7 +230,7 @@ func ActionModify(cmd *dclish.Command) error {
// This originally existed as the subroutine REMOVE_FOLDER in bulletin5.for.
func ActionRemove(cmd *dclish.Command) error {
	if this.User.Login != this.Folder.Owner && this.User.Admin == 0 {
		return errors.New("must be folder owner or admin to delete the folder")
		return errors.New("you are not able to remove the folder")
	}
	if this.Folder.Name == "GENERAL" {
		return errors.New("can't delete folder GENERAL")
+2 −2
Original line number Diff line number Diff line
@@ -199,12 +199,12 @@ func ActionRespond(cmd *dclish.Command) error {
		return nil
	}
	if this.MsgID == 0 {
		return errors.New("no current message to respond to")
		return errors.New("you have not read any message")
	}
	ctx := storage.Context()
	msg, err := this.Q.ReadMessage(ctx, this.Folder.Name, this.MsgID)
	if err != nil {
		return errors.New("failed to read current message")
		return errors.New("bulletin was not found")
	}

	recipient := msg.Author
+9 −5
Original line number Diff line number Diff line
@@ -364,7 +364,7 @@ func ActionCurrent(_ *dclish.Command) error {
func ActionBack(_ *dclish.Command) error {
	msgid := folders.PrevMsgid(this.User.Login, this.Folder.Name, this.MsgID)
	if msgid == 0 {
		fmt.Println("No previous messages")
		fmt.Println("ERROR: There are no more preceding messages.")
		return nil
	}
	msg, err := folders.GetMessage(this.User.Login, this.Folder.Name, msgid)
@@ -623,7 +623,7 @@ func ActionLast(_ *dclish.Command) error {
func ActionNext(_ *dclish.Command) error {
	msgid := folders.NextMsgid(this.User.Login, this.Folder.Name, this.MsgID)
	if msgid == 0 {
		fmt.Println("No next messages")
		fmt.Println("No more messages.")
		return nil
	}
	msg, err := folders.GetMessage(this.User.Login, this.Folder.Name, msgid)
@@ -695,7 +695,7 @@ func ActionRead(cmd *dclish.Command) error {
			return err
		}
		if id == 0 {
			fmt.Println("No unread messages.")
			fmt.Println("No new messages are present.")
			return nil
		}
		msgid = id
@@ -801,6 +801,10 @@ func ActionReply(cmd *dclish.Command) error {
	if cmd.Flags["/INDENT"].Value == "false" {
		indent = false
	}
	if this.MsgID == 0 {
		fmt.Println("ERROR: You have not read any message.")
		return nil
	}
	original, err := folders.GetMessage(this.User.Login, this.Folder.Name, this.MsgID)
	if err != nil {
		fmt.Printf("ERROR: GetMessage failure (%s).\n", err)
@@ -910,7 +914,7 @@ func ActionDelete(cmd *dclish.Command) error {
		}
	}
	if this.User.Admin == 0 && this.User.Moderator == 0 && !folders.WroteAllMessages(this.User.Login, msgids) {
		return errors.New("can't delete messages you haven't written")
		return errors.New("message was not deleted. Not owned by you")
	}
	err = folders.DeleteMessages(msgids)
	if err != nil {
@@ -1082,7 +1086,7 @@ func ActionSearch(cmd *dclish.Command) error {
	}

	if len(allMsgs) == 0 {
		fmt.Println("No messages found.")
		fmt.Println("No messages found with given search string.")
		return nil
	}
	buf := strings.Builder{}
+6 −6
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ func ActionSetNobrief(cmd *dclish.Command) error {
// ActionSetDefaultExpire handles the `SET DEFAULT_EXPIRE` command.
func ActionSetDefaultExpire(cmd *dclish.Command) error {
	if this.User.Admin == 0 {
		return errors.New("you are not an admin")
		return errors.New("privileges needed for changing defaults")
	}
	value, err := strconv.ParseInt(cmd.Args[0], 10, 64)
	if err != nil {
@@ -188,7 +188,7 @@ func ActionSetDefaultExpire(cmd *dclish.Command) error {
// ActionSetExpireLimit handles the `SET EXPIRE_LIMIT` command.
func ActionSetExpireLimit(cmd *dclish.Command) error {
	if this.User.Admin == 0 {
		return errors.New("you are not an admin")
		return errors.New("privileges needed for changing defaults")
	}
	value, err := strconv.ParseInt(cmd.Args[0], 10, 64)
	if err != nil {
@@ -233,7 +233,7 @@ func ActionSetNoShowNew(cmd *dclish.Command) error {
// ActionSetSystem handles the `SET SYSTEM` command.
func ActionSetSystem(_ *dclish.Command) error {
	if this.User.Admin == 0 {
		return errors.New("you are not an admin")
		return errors.New("privileges needed for changing defaults")
	}
	ctx := storage.Context()
	return this.Q.UpdateFolderSystem(ctx, 1, this.Folder.Name)
@@ -242,7 +242,7 @@ func ActionSetSystem(_ *dclish.Command) error {
// ActionSetNosystem handles the `SET SYSTEM` command.
func ActionSetNosystem(_ *dclish.Command) error {
	if this.User.Admin == 0 {
		return errors.New("you are not an admin")
		return errors.New("privileges needed for changing defaults")
	}
	if this.Folder.Name == "GENERAL" {
		fmt.Println("Can't remove SYSTEM from the GENERAL folder.")
@@ -255,7 +255,7 @@ func ActionSetNosystem(_ *dclish.Command) error {
// ActionSetRegistration handles the `SET REGISTRATION` command.
func ActionSetRegistration(cmd *dclish.Command) error {
	if this.User.Admin == 0 {
		return errors.New("you are not an admin")
		return errors.New("privileges needed for changing defaults")
	}
	if len(cmd.Args) != 1 {
		fmt.Println("Usage: SET REGISTRATION OPEN|CLOSED")
@@ -292,7 +292,7 @@ func ActionSetRegistration(cmd *dclish.Command) error {
// ActionSetShibboleth handles the `SET SHIBBOLETH` command.
func ActionSetShibboleth(_ *dclish.Command) error {
	if this.User.Admin == 0 {
		return errors.New("you are not an admin")
		return errors.New("privileges needed for changing defaults")
	}
	ctx := storage.Context()

+1 −1
Original line number Diff line number Diff line
@@ -192,7 +192,7 @@ func ActionShowUser(cmd *dclish.Command) error {
				return err
			}
			if folder.Name == "" {
				fmt.Println("ERROR: Folder does not exist.")
				fmt.Println("ERROR: Folder not found.")
				return nil
			}
		}
Loading