1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-29 03:17:53 -04:00

Cleanup and improve error messaging

Script errors are now reported either with WDBG() at startup, ERROR()
if SEE decides to abort and using info_box() for everything else, including
script runtime errors.
This commit is contained in:
Jonas Fonseca 2005-10-24 00:57:47 +02:00 committed by Jonas Fonseca
parent 9e97a100e2
commit bc0cc67fd9
3 changed files with 47 additions and 36 deletions

View File

@ -23,21 +23,7 @@
#define SEE_HOOKS_FILENAME "hooks.js"
struct SEE_interpreter see_interpreter;
struct SEE_object *see_browser_object;
#if 0
/* SEE strings */
static struct SEE_string[] = {
{ 'E', 'L', 'i', 'n', 'k', 's' },
{ "goto-url", 0, script_hook_goto_url, NULL },
{ "follow-url", 0, script_hook_follow_url, NULL },
{ "pre-format-html", 0, script_hook_pre_format_html, NULL },
{ "get-proxy", 0, script_hook_get_proxy, NULL },
{ "quit", 0, script_hook_quit, NULL },
{ 0 },
};
#endif
struct string *
convert_see_string(struct string *string, struct SEE_string *source)
@ -83,7 +69,7 @@ elinks_see_write(struct SEE_interpreter *see, struct SEE_object *self,
return;
if (list_empty(terminals)) {
usrerror("[SEE] ", string.source);
usrerror("[SEE] %s", string.source);
done_string(&string);
return;
}
@ -92,19 +78,21 @@ elinks_see_write(struct SEE_interpreter *see, struct SEE_object *self,
N_("SEE Message"), ALIGN_LEFT, string.source);
}
#if 0
#if DATADRIVEN
_IDEA
struct object_info browser_object[] = {
"ELinks",
"ELinks", SEE_ATTR_READONLY,
{ /* Properties: */
{ "version", SEE_STRING, VERSION, SEE_READONLY },
{ "home", ... },
{ NULL }
{ "version", SEE_STRING, VERSION, SEE_ATTR_READONLY },
{ "home", SEE_STRING, NULL, SEE_ATTR_READONLY },
},
{ /* Methods: (as name, handler, args) */
{ "write", elinks_see_write, 1 },
{ "write", elinks_see_write, SEE_ATTR_READONLY },
{ NULL }
},
};
struct object_info *see_
#endif
static void
@ -123,7 +111,7 @@ init_see_environment(struct SEE_interpreter *see)
elinks = SEE_Object_new(see);
SEE_SET_OBJECT(&value, elinks);
name = SEE_string_sprintf(see, "ELinks");
SEE_OBJECT_PUT(see, see->Global, name, &value, 0);
SEE_OBJECT_PUT(see, see->Global, name, &value, SEE_ATTR_READONLY);
/* Create a string and attach as 'ELinks.version' */
SEE_SET_STRING(&value, SEE_string_sprintf(see, VERSION));
@ -146,7 +134,8 @@ init_see_environment(struct SEE_interpreter *see)
static void
see_abort_handler(struct SEE_interpreter *see, const char *msg)
{
alert_see_error(NULL, (unsigned char *) msg);
ERROR((unsigned char *) msg);
/* TODO: reload scripts! */
}
static void
@ -186,6 +175,7 @@ init_see(struct module *module)
struct SEE_input *input;
SEE_try_context_t try_context;
struct SEE_value *exception;
struct string error_msg;
/* Load ~/.elinks/hooks.js into the interpreter. */
input = SEE_input_file(see, file, path, NULL);
@ -196,31 +186,31 @@ init_see(struct module *module)
SEE_INPUT_CLOSE(input);
exception = SEE_CAUGHT(try_context);
if (exception) {
if (exception && init_string(&error_msg)) {
SEE_try_context_t try_context2;
struct SEE_value value;
fprintf(stderr, "errors encountered while reading %s:", path);
SEE_TRY(see, try_context2) {
SEE_ToString(see, exception, &value);
SEE_string_fputs(value.u.string, stderr);
convert_see_string(&error_msg, value.u.string);
#if 0
if (ctxt.throw_file)
fprintf(stderr, " (thrown from %s:%d)\n",
ctxt.throw_file, ctxt.throw_line);
#endif
SEE_PrintTraceback(see, stderr);
}
WDBG("errors encountered while reading %s:\n%s", path, error_msg.source);
done_string(&error_msg);
if (SEE_CAUGHT(try_context2)) {
fprintf(stderr, "exception thrown while "
WDBG("exception thrown while "
"printing exception");
#if 0
if (ctxt2.throw_file)
fprintf(stderr, " at %s:%d",
ctxt2.throw_file, ctxt2.throw_line);
#endif
fprintf(stderr, "\n");
}
}
}

View File

@ -9,7 +9,6 @@ struct session;
struct string;
extern struct SEE_interpreter see_interpreter;
extern struct SEE_object *see_browser_object;
struct string *convert_see_string(struct string *string, struct SEE_string *source);
void alert_see_error(struct session *ses, unsigned char *msg);

View File

@ -27,6 +27,8 @@ call_see_hook(struct SEE_interpreter *see, unsigned char *name,
{
struct SEE_string *hook_name = SEE_string_sprintf(see, name);
struct SEE_value hook;
SEE_try_context_t try_context;
struct SEE_value *exception;
SEE_OBJECT_GET(see, see->Global, hook_name, &hook);
@ -34,13 +36,33 @@ call_see_hook(struct SEE_interpreter *see, unsigned char *name,
|| !SEE_OBJECT_HAS_CALL(hook.u.object))
return NULL;
SEE_OBJECT_CALL(see, hook.u.object, NULL, argc, args, result);
#if 0
if (error) {
erb_report_error(NULL, error);
return EVENT_HOOK_STATUS_NEXT;
SEE_TRY(see, try_context) {
SEE_OBJECT_CALL(see, hook.u.object, NULL, argc, args, result);
}
exception = SEE_CAUGHT(try_context);
if (exception) {
SEE_try_context_t try_context2;
struct SEE_value value;
SEE_TRY(see, try_context2) {
struct string error_msg;
SEE_ToString(see, exception, &value);
if (init_string(&error_msg)) {
convert_see_string(&error_msg, value.u.string);
alert_see_error(NULL, error_msg.source);
done_string(&error_msg);
}
}
if (SEE_CAUGHT(try_context2)) {
WDBG("exception thrown while printing exception");
}
return NULL;
}
#endif
return result;
}