Clean up error messages displayed in the error box - #756
Conversation
| ); | ||
| await showMessageBox( event, { | ||
|
|
||
| console.error( filteredError ); |
There was a problem hiding this comment.
Let's not make this method responsible of logging the error and leave it up for the caller.
Given #753, we could clean logic around filteredError and error in this method.
There was a problem hiding this comment.
I think it would be preferable to display the error twice than none.
We could display some empty lines and a clear text in the log, like: "ERROR REPORTED:" or "ERROR OCCURRED:". This way the user and we would be much more sure about what error was the responsible of the alert.
Here is a possible implementation:
const errorMessage = ( error as Error )?.message;
if ( errorMessage ) {
console.error( '\n\n\n\n\n\nERROR REPORTED:\n' + errorMessage );
}
If we follow this path, we could rename the parameter name from error to errorToLog, so it's clear that the error will be logged in this function.
This is an example of how it would look:
I also see Wojtek's point of view from the perspective of a single responsibility, so open to other ideas.
There was a problem hiding this comment.
Yes, let's remove the logging from this error and filteredError handling as those are solved outside the method scope.
Co-authored-by: Wojtek Naruniec <wojtek.naruniec@automattic.com>
sejas
left a comment
There was a problem hiding this comment.
Code looks good, and it works as expected.
Not approving it until we decide if we should log or not the error.
I also see a possibility to display the first line of characters of the error inside the alert, that way users could share a screenshot of Studio too. But it's not a strong opinion.
I wonder if there are errors where we show the alert and we don't log them into the file. Then in those cases the "Open Studio logs" button would be misleading.
I only tested it on Mac:
Clicking the Open Studio logs it opens the console app with the correct file almost at the bottom:
| ); | ||
| await showMessageBox( event, { | ||
|
|
||
| console.error( filteredError ); |
There was a problem hiding this comment.
I think it would be preferable to display the error twice than none.
We could display some empty lines and a clear text in the log, like: "ERROR REPORTED:" or "ERROR OCCURRED:". This way the user and we would be much more sure about what error was the responsible of the alert.
Here is a possible implementation:
const errorMessage = ( error as Error )?.message;
if ( errorMessage ) {
console.error( '\n\n\n\n\n\nERROR REPORTED:\n' + errorMessage );
}
If we follow this path, we could rename the parameter name from error to errorToLog, so it's clear that the error will be logged in this function.
This is an example of how it would look:
I also see Wojtek's point of view from the perspective of a single responsibility, so open to other ideas.
| detail: error ? `${ message }\n\nError: ${ filteredError }` : message, | ||
| buttons: [ __( 'OK' ) ], | ||
| detail: message, | ||
| buttons: [ __( 'Open Studio logs' ), __( 'OK' ) ], |
There was a problem hiding this comment.
Should we display the "Open Studio logs" buttons in all the cases? or just when we receive the "errorToLog" parameter?
There was a problem hiding this comment.
Good point! We could use a param, e.g. showOpenLogs, that is set to false by default, and we can enable it per the case.
| const response = await showMessageBox( event, { | ||
| type: 'error', | ||
| message: title, | ||
| detail: error ? `${ message }\n\nError: ${ filteredError }` : message, |
There was a problem hiding this comment.
Let's bring it back so the specific error can still be appended, but let's drop the 'Error: '.
| ); | ||
| await showMessageBox( event, { | ||
|
|
||
| console.error( filteredError ); |
There was a problem hiding this comment.
Yes, let's remove the logging from this error and filteredError handling as those are solved outside the method scope.
| detail: error ? `${ message }\n\nError: ${ filteredError }` : message, | ||
| buttons: [ __( 'OK' ) ], | ||
| detail: message, | ||
| buttons: [ __( 'Open Studio logs' ), __( 'OK' ) ], |
There was a problem hiding this comment.
Good point! We could use a param, e.g. showOpenLogs, that is set to false by default, and we can enable it per the case.
|
@bcotrim my bad, I was wrong on |
| "Please verify your site's local path directory contains the standard WordPress installation files and try again. If this problem persists, please contact support." | ||
| ), | ||
| error, | ||
| showOpenLogs: true, |
There was a problem hiding this comment.
I'm enabling a new button for cases in which Studio can't start the site.
Will add more under https://github.com/Automattic/dotcom-forge/issues/10143
Related issues
Proposed Changes
showErrorMessageBoxTesting Instructions
Prerequisites
npm startTest Scenarios
Error Dialog Display
showOpenLogsis trueLog File Access
Dialog Dismissal
Expected Results
showErrorMessageBoxfunctionPre-merge Checklist