Python errors originating in the active text are now displayed at the top of the text area. Errors in other files/scripts still pop up a message as before and all errors are still printed to the console. This removes the need to switch to the console for local errors.

This commit is contained in:
2008-08-09 18:11:40 +00:00
parent 4c89ee7838
commit 83bcb9deff
3 changed files with 45 additions and 4 deletions

View File

@@ -145,9 +145,11 @@ static struct _inittab BPy_Inittab_Modules[] = {
* Structure definitions
**************************************************************************/
#define FILENAME_LENGTH 24
#define MESSAGE_LENGTH 256
typedef struct _ScriptError {
char filename[FILENAME_LENGTH];
char message[MESSAGE_LENGTH+1];
int lineno;
} ScriptError;
@@ -507,6 +509,15 @@ const char *BPY_Err_getFilename( void )
return g_script_error.filename;
}
/*****************************************************************************/
/* Description: This function will return the short message of the error */
/* that has occured in the python script. */
/*****************************************************************************/
const char *BPY_Err_getMessage( void )
{
return g_script_error.message;
}
/*****************************************************************************/
/* Description: Return PyString filename from a traceback object */
/*****************************************************************************/
@@ -566,6 +577,15 @@ void BPY_Err_Handle( char *script_name )
} else {
g_script_error.lineno = -1;
}
v = PyObject_GetAttrString( err, "text" );
if ( v && PyString_Check(v) ) {
strcpy(g_script_error.message, "Invalid syntax: ");
strncpy(g_script_error.message+16, PyString_AS_STRING( v ), MESSAGE_LENGTH-16);
g_script_error.message[MESSAGE_LENGTH]= '\0';
Py_DECREF( v );
} else {
strcpy(g_script_error.message, "Invalid Syntax");
}
/* this avoids an abort in Python 2.3's garbage collecting: */
PyErr_Clear( );
return;
@@ -612,6 +632,14 @@ void BPY_Err_Handle( char *script_name )
FILENAME_LENGTH );
Py_DECREF(v);
}
v = PyObject_GetAttrString( err, "message" );
if ( v && PyString_Check(v) ) {
strncpy(g_script_error.message, PyString_AS_STRING( v ), MESSAGE_LENGTH);
g_script_error.message[MESSAGE_LENGTH]= '\0';
Py_DECREF( v );
} else {
g_script_error.message[0] = '\0';
}
Py_DECREF( tb );
}