Feature request for plugin MessageBox

Hi Guys,

When using the messageBox plugin for error reporting, I notice that I get my errors mainly in reverse order of how I would like to display them. Let me give a small example:
I know the example is very simple, and in this case we could set the entire message in the DAO, but for different cases the function in the DAO may be called from other handlers and other service layers… SO bear with me.

Suppose we have a handler called Admin:

component {

property name=“adminService” inject=“adminService@services”;

function index(event,rc,prc){
setNextEvent(“admin/tasks”);
}

function tasks(event,rc,prc){
event.paramValue(“tab”,0);
event.setView(“admin/tasks”);
}

/**

  • saveBranch
    */
    function saveBranch(event,rc,prc){
    event.paramValue(“branchName”,"");
    event.paramValue(“branchCity”,"");

var messageBox = getPlugin(“MessageBox”);
var branchSaved = adminService.saveBranch(rc.branchName, rc.closeMatch, messageBox);

if(!branchSaved){
messageBox.appendArray([“Saving of branch failed:”]);
} else {
messageBox.setMessage(type=“info”, message=“Branch saved succesfully.”);
}
setNextEvent(“admin/tasks”);
}

}

Now the AdminService service layer:

/**

  • Admin Service Layer
    */
    component singleton=“true” {

property name=“myDAO” inject=“MyDAO@dao”;

AdminService function init(){

return this;
}

boolean function saveBranch(required string branchName, required string cityName, required any messageBox) {
var result = myDAO.saveBranch(branchName, cityName, messageBox);

if (!result) {
messageBox.appendArray([“Call to AdminService.saveBranch failed.”]);
}

return result;
}

}

And for the DAO:

component singleton=“true” {

property name=“dsn” inject=“coldbox:datasource:avisDSN”;

boolean function saveBranch(required string branchName, required string cityName, required any messageBox){
try {
// Do the query to update or insert the branch
// … //
} catch (any e) {
messageBox.setMessage(type=“error”,messageArray=[e.message]);
return false;
}
return true;
}
}

An error would result in the following messageArray:
[
“Some SQL error”,
“Call to AdminService.saveBranch failed.”,
“Saving of branch failed:”
]

While it would make more sense to have it like this:

[
“Saving of branch failed:”,
“Call to AdminService.saveBranch failed.”,
“Some SQL error”
]

I know I can fabricate this by getting the message, concat my own message to the front and then setting the message again, but would it not be nice to have functionality to do this for me?

So my feature request would be for a messageBox.prependArray().

var currentMessage = ""; var newMessage = "";

// Do we have a message?
if( isEmpty() ){
// Set default message
setMessage(type=‘information’,messageArray=arguments.messageArray);
}
else{
// Get Current Message
currentMessage = getMessage();
// Append
ArrayPrePend(currentMessage.message,arguments.messageArray);
// Set it back
setMessage(type=currentMessage.type,messageArray=arguments.messageArray);
}

This is the altered version of appendArray in the messageBox plugin. I would want to note that the implementation of appendArray is a bit strange as it uses the ArrayPrepend function with the arguments in reverse. For readability I would rather use the ArrayAppend function with the arguments in the correct order :slight_smile:

At the moment I have a custom plugin that extends the MessageBox plugin, but wouldn’t this be nice to be added in the core plugin?