touched up error message handling

This commit is contained in:
hyunghwan.chung 2018-02-12 16:50:32 +00:00
parent b64fdb0019
commit 88861aa522
2 changed files with 24 additions and 16 deletions

View File

@ -542,8 +542,10 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags)
if (!handle) if (!handle)
{ {
moo_bch_t* dash; moo_bch_t* dash;
moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open(ext) DL %js - %hs", name, sys_dl_error()); const moo_bch_t* dl_errstr;
MOO_DEBUG3 (moo, "Failed to open(ext) DL %hs[%js] - %hs\n", &bufptr[len], name, sys_dl_error()); dl_errstr = sys_dl_error();
MOO_DEBUG3 (moo, "Failed to open(ext) DL %hs[%js] - %hs\n", &bufptr[len], name, dl_errstr);
moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open(ext) DL %js - %hs", name, dl_errstr);
dash = moo_rfindbchar(bufptr, moo_countbcstr(bufptr), '-'); dash = moo_rfindbchar(bufptr, moo_countbcstr(bufptr), '-');
if (dash) if (dash)
{ {
@ -580,8 +582,10 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags)
handle = sys_dl_open(bufptr); handle = sys_dl_open(bufptr);
if (!handle) if (!handle)
{ {
moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open DL %js - %hs", name, sys_dl_error()); const moo_bch_t* dl_errstr;
MOO_DEBUG2 (moo, "Failed to open DL %hs - %hs\n", bufptr, sys_dl_error()); dl_errstr = sys_dl_error();
MOO_DEBUG2 (moo, "Failed to open DL %hs - %hs\n", bufptr, dl_errstr);
moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open DL %js - %hs", name, dl_errstr);
} }
else MOO_DEBUG2 (moo, "Opened DL %hs handle %p\n", bufptr, handle); else MOO_DEBUG2 (moo, "Opened DL %hs handle %p\n", bufptr, handle);
} }
@ -590,8 +594,10 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags)
handle = sys_dl_openext(bufptr); handle = sys_dl_openext(bufptr);
if (!handle) if (!handle)
{ {
moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open(ext) DL %js - %hs", name, sys_dl_error()); const moo_bch_t* dl_errstr;
MOO_DEBUG2 (moo, "Failed to open(ext) DL %hs - %hs\n", bufptr, sys_dl_error()); dl_errstr = sys_dl_error();
MOO_DEBUG2 (moo, "Failed to open(ext) DL %hs - %hs\n", bufptr, dl_errstr);
moo_seterrbfmt (moo, MOO_ESYSERR, "unable to open(ext) DL %js - %hs", name, dl_errstr);
} }
else MOO_DEBUG2 (moo, "Opened(ext) DL %hs handle %p\n", bufptr, handle); else MOO_DEBUG2 (moo, "Opened(ext) DL %hs handle %p\n", bufptr, handle);
} }
@ -679,7 +685,10 @@ static void* dl_getsym (moo_t* moo, void* handle, const moo_ooch_t* name)
sym = sys_dl_getsym(handle, symname); sym = sys_dl_getsym(handle, symname);
if (!sym) if (!sym)
{ {
moo_seterrbfmt (moo, MOO_ENOENT, "unable to get module symbol %hs", symname); const moo_bch_t* dl_errstr;
dl_errstr = sys_dl_error();
MOO_DEBUG3 (moo, "Failed to get module symbol %js from handle %p - %hs\n", name, handle, dl_errstr);
moo_seterrbfmt (moo, MOO_ENOENT, "unable to get module symbol %hs - %hs", symname, dl_errstr);
} }
} }
} }

View File

@ -496,7 +496,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel
/* TODO: binary search ... */ /* TODO: binary search ... */
for (n = 0; n < MOO_COUNTOF(static_modtab); n++) for (n = 0; n < MOO_COUNTOF(static_modtab); n++)
{ {
if (moo_compoocharsbcstr (name, namelen, static_modtab[n].modname) == 0) if (moo_compoocharsbcstr(name, namelen, static_modtab[n].modname) == 0)
{ {
load = static_modtab[n].modload; load = static_modtab[n].modload;
break; break;
@ -513,7 +513,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel
/* i copy-insert 'md' into the table before calling 'load'. /* i copy-insert 'md' into the table before calling 'load'.
* to pass the same address to load(), query(), etc */ * to pass the same address to load(), query(), etc */
pair = moo_rbt_insert (&moo->modtab, (moo_ooch_t*)name, namelen, &md, MOO_SIZEOF(md)); pair = moo_rbt_insert(&moo->modtab, (moo_ooch_t*)name, namelen, &md, MOO_SIZEOF(md));
if (pair == MOO_NULL) if (pair == MOO_NULL)
{ {
moo_seterrnum (moo, MOO_ESYSMEM); moo_seterrnum (moo, MOO_ESYSMEM);
@ -523,7 +523,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel
mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair); mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair);
MOO_ASSERT (moo, MOO_SIZEOF(mdp->mod.hints) == MOO_SIZEOF(int)); MOO_ASSERT (moo, MOO_SIZEOF(mdp->mod.hints) == MOO_SIZEOF(int));
mdp->mod.hints = hints; mdp->mod.hints = hints;
if (load (moo, &mdp->mod) <= -1) if (load(moo, &mdp->mod) <= -1)
{ {
moo_rbt_delete (&moo->modtab, (moo_ooch_t*)name, namelen); moo_rbt_delete (&moo->modtab, (moo_ooch_t*)name, namelen);
return MOO_NULL; return MOO_NULL;
@ -555,7 +555,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel
moo_copyoochars ((moo_ooch_t*)md.mod.name, name, namelen); moo_copyoochars ((moo_ooch_t*)md.mod.name, name, namelen);
if (moo->vmprim.dl_open && moo->vmprim.dl_getsym && moo->vmprim.dl_close) if (moo->vmprim.dl_open && moo->vmprim.dl_getsym && moo->vmprim.dl_close)
{ {
md.handle = moo->vmprim.dl_open (moo, &buf[MOD_PREFIX_LEN], MOO_VMPRIM_OPENDL_PFMOD); md.handle = moo->vmprim.dl_open(moo, &buf[MOD_PREFIX_LEN], MOO_VMPRIM_OPENDL_PFMOD);
} }
if (md.handle == MOO_NULL) if (md.handle == MOO_NULL)
@ -566,11 +566,10 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel
} }
/* attempt to get moo_mod_xxx where xxx is the module name*/ /* attempt to get moo_mod_xxx where xxx is the module name*/
load = moo->vmprim.dl_getsym (moo, md.handle, buf); load = moo->vmprim.dl_getsym(moo, md.handle, buf);
if (!load) if (!load)
{ {
const moo_ooch_t* oldmsg = moo_backuperrmsg (moo); moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to get module symbol [%js] in [%.*js] - %js", buf,namelen, name);
moo_seterrbfmt (moo, moo_geterrnum(moo), "unable to get module symbol [%js] in [%.*js] - %js", buf,namelen, name, oldmsg);
MOO_DEBUG3 (moo, "Cannot get a module symbol [%js] in [%.*js]\n", buf, namelen, name); MOO_DEBUG3 (moo, "Cannot get a module symbol [%js] in [%.*js]\n", buf, namelen, name);
moo->vmprim.dl_close (moo, md.handle); moo->vmprim.dl_close (moo, md.handle);
return MOO_NULL; return MOO_NULL;
@ -578,7 +577,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel
/* i copy-insert 'md' into the table before calling 'load'. /* i copy-insert 'md' into the table before calling 'load'.
* to pass the same address to load(), query(), etc */ * to pass the same address to load(), query(), etc */
pair = moo_rbt_insert (&moo->modtab, (void*)name, namelen, &md, MOO_SIZEOF(md)); pair = moo_rbt_insert(&moo->modtab, (void*)name, namelen, &md, MOO_SIZEOF(md));
if (pair == MOO_NULL) if (pair == MOO_NULL)
{ {
MOO_DEBUG2 (moo, "Cannot register a module [%.*js]\n", namelen, name); MOO_DEBUG2 (moo, "Cannot register a module [%.*js]\n", namelen, name);
@ -590,7 +589,7 @@ moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namel
mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair); mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair);
MOO_ASSERT (moo, MOO_SIZEOF(mdp->mod.hints) == MOO_SIZEOF(int)); MOO_ASSERT (moo, MOO_SIZEOF(mdp->mod.hints) == MOO_SIZEOF(int));
mdp->mod.hints = hints; mdp->mod.hints = hints;
if (load (moo, &mdp->mod) <= -1) if (load(moo, &mdp->mod) <= -1)
{ {
const moo_ooch_t* oldmsg = moo_backuperrmsg (moo); const moo_ooch_t* oldmsg = moo_backuperrmsg (moo);
moo_seterrbfmt (moo, moo_geterrnum(moo), "module initializer [%js] returned failure in [%.*js] - %js", buf, namelen, name, oldmsg); moo_seterrbfmt (moo, moo_geterrnum(moo), "module initializer [%js] returned failure in [%.*js] - %js", buf, namelen, name, oldmsg);