Skip to content

Conversation

gerald2545
Copy link

check if mattermost user to send message to is empty (Users parameter in conf file)
in case Users is not empty, a call to mattermost was done to get the user id of Mattermost Username/accesstoken. This call was already done on first login. Si I set UserId attribute at login

Sorry, I didn't manage to make mage work (mage test : Unknown target specified: "test")

Copy link
Contributor

@c-seeger c-seeger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gerald2545 for taking the time to create this pull request ❤️

err := m.PostMattermost(p, mail)
if err != nil {
m.Error("Mattermost Error", map[string]interface{}{
m.Error("Right after PostMattermost, Mattermost Error. Email not set as synced in mattermost.", map[string]interface{}{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be more like

m.Error("Mattermost Error", map[string]interface{}{
"call": "PostMattermost",
"error": err
})

I think the "Email not set as synced" part can be removed this its now the correct default behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for reference: putting additional information into the additional information part (map[string]interface) allows the logger to seperate this information and depending on the logging type (text/json) to seperate the fields so they can be read and parsed by a logging backend correctly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you fix it pls

m.Error("File Error", map[string]interface{}{
"Error": err,
})
m.Debug("In mail2most Run, Before writeToFile on " + m.Config.General.File,nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put the additional logging information into map[string]interface{}

m.Debug("writing to file", map[string]interface{
"filename": m.Config.General.File,
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

func (m Mail2Most) mlogin(profile int) (*model.Client4, error) {
c := model.NewAPIv4Client(m.Config.Profiles[profile].Mattermost.URL)

m.Info("in mlogin", nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m.Debug("login", map[string]interface{
"profile": profile,
})

no need to have this on Info logging

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

user, resp := c.GetUserByEmail(email, "")
if resp.Error != nil {
m.Debug("user not found in system", map[string]interface{}{"error": resp.Error})
m.Debug("user not found in system for email " + email, map[string]interface{}{"error": resp.Error})
Copy link
Contributor

@c-seeger c-seeger Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m.Debug("user not found", map[string]interface{}{
  "error": resp.Error, 
  "email": email,
  "call": "GetUserByEmail",
  })

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be more precise I think
email sender not defined as mattermost user

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about

m.Debug("user not found", map[string]interface{}{
  "error": resp.Error, 
  "email": email,
  "call": "GetUserByEmail",
  "note": "email sender not defined as mattermost user",
  })

}
}

//m.Debug("Before SubjectOnly/BodyOnly " + err.Error,nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed i guess?

}
}

m.Debug("In PostMattermost, Before m.Config.Profiles[profile].Mattermost.Users treatment",nil)
Copy link
Contributor

@c-seeger c-seeger Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the others, adding additional information as seperate

var (
u *model.User
)
m.Debug("In PostMattermost, In m.Config.Profiles[profile].Mattermost.Users treatment ", map[string]interface{}{"length of user name": len(user)})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is debug line is really needed since it's now catched with a proper error instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map[string]interface{}{"length of user name": len(user)} since it is used to allow the logger to create parsable key value pairs the key should follow usual naming standards e.g: username_length. Also what benefit is created by this debug line providing user length as information for debugging?

@c-seeger
Copy link
Contributor

for the mage part magefile

you can use mage to see all commands available, equal to make since mage is a make replacement but instead of a makefile you have a magefile that can be written in golang.

output should be sth. like this:

Targets:
  docker:cleanDocker    Clean - removes docker build files
  docker:docker         - creates docker container
  docker:init           - initializes docker build requirements
  release:all           - mage build all releases
  service:build         - mage build
  service:run           - mage run
  test:clean            - cleans up the client generation and binarys
  test:coverage         - checking code coverage
  test:run              - running tests and code coverage

relevant commands are mage test:run to run the tests (you can also just use the native go command go test -v ./...) and mage service:run so you can just run the code and see if it works with your configuration

@gerald2545
Copy link
Author

OK, I'll test mage command, I guess I didn't use the right ones "mage test" instead of "mage test:run" and "mage build" instead of "mage service:build"

I used the "mage build" command as found in README > build it yourself, if it's not the right one you chould update it ;)

@gerald2545
Copy link
Author

OK, I'll test mage command, I guess I didn't use the right ones "mage test" instead of "mage test:run" and "mage build" instead of "mage service:build"

I used the "mage build" command as found in README > build it yourself, if it's not the right one you chould update it ;)

with the right command, it works better ;)

@gerald2545
Copy link
Author

README updated in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants