How to handle error message output with escape codes?

...I have a Shiny application that connects to Oracle database with ODBC protocol.
I want to make a nice error notification if a bad query has been passed to DB.
After establishing connection, I pass a query to dbGetQuery(pool,v_query) and use tryCatch() to process result.
here is my 'error' function:

error=function(e) {
            showModal(modalDialog(
              title = "Query Failed",
              tags$b("Error:"), br(),
              tags$code(conditionMessage(e))
            ))
            cat(conditionMessage(e))
          })

while cat() generates a readable text, in modal dialog window I see a string full of escape characters.
Here is patrial cat() output:

 Evaluation error: ! ODBC failed with error 00000 from [Oracle][ODBC][Ora].
 ✖ ORA-00942: table or view does not exist
 • 
 • <SQL> 'SELECT

Here is the partial output from tags$code(conditionMessage(e)):

Evaluation error: e[38;5;232me[33m!e[38;5;232m ODBC failed with error 00000 from e[32m[Oracle][ODBC][Ora]e[38;5;232m. e[31m✖e[38;5;232m ORA-00942: table or view does not exist e[36m•e[38;5;232m e[36m•e[38;5;232m <SQL> 'SELECT

I tried to use textOutput(conditionMessage(e) but application crashes with the error:
No handler registered for type .clientdata_output_Evaluation error: ! ODBC failed with error 00000...

Is there a simple way to display error output in modalDialog with correct formatting?

There is a rule of thumb: if you tried all you can and totally gave up, you have to ask for help on some forum and immediately after that (but before anyone's response) you will find the solution!
So one solution is: install library "cli" and use function
ansi_strip(e$message, sgr = TRUE, csi = TRUE, link = TRUE)

:smiley:

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.