Ignore:
Timestamp:
Feb 11, 2015, 11:29:35 AM (9 years ago)
Author:
djay
Message:

Code cleanup, description of some functon included in the code, addition of support for multiple error output, beter internal gesture of MapArray?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r539 r576  
    215215  }
    216216  else{
    217     map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file.");
    218     addToMap(err,"code","NoApplicableCode");
    219     printExceptionReportResponse(m,err);
     217    errorException (m, "Unable to parse serviceProvider please check your zcfg file.", "NoApplicableCode", NULL);
    220218    exit(-1);
    221219  }
     
    250248#endif
    251249      }else{     
    252         PyObject *ptype,*pvalue, *ptraceback;
    253         PyErr_Fetch(&ptype, &pvalue, &ptraceback);
    254         PyObject *trace=PyObject_Str(pvalue);
    255         char pbt[10240];
    256         if(PyString_Check(trace))
    257           sprintf(pbt,"TRACE : %s",PyString_AsString(trace));
    258         else
    259           fprintf(stderr,"EMPTY TRACE ?");
    260         trace=NULL;
    261         trace=PyObject_Str(ptype);
    262         if(PyString_Check(trace)){
    263           char *tpbt=zStrdup(pbt);
    264           sprintf(pbt,"%s\n%s",tpbt,PyString_AsString(trace));
    265           free(tpbt);
    266         }
    267         else
    268           fprintf(stderr,"EMPTY TRACE ?");
    269        
    270         char *tpbt=zStrdup(pbt);
    271         pName = PyString_FromString("traceback");
    272         pModule = PyImport_Import(pName);
    273         pArgs = PyTuple_New(1);
    274         PyTuple_SetItem(pArgs, 0, ptraceback);
    275         pFunc = PyObject_GetAttrString(pModule,"format_tb");
    276         pValue = PyObject_CallObject(pFunc, pArgs);
    277         trace=NULL;
    278         trace=PyObject_Str(pValue);
    279         if(PyString_Check(trace))
    280           sprintf(pbt,"%s\nUnable to run your python process properly. Please check the following messages : %s",tpbt,PyString_AsString(trace));
    281         else
    282           sprintf(pbt,"%s \n Unable to run your python process properly. Unable to provide any futher informations.",tpbt);
    283         free(tpbt);
    284         map* err=createMap("text",pbt);
    285         addToMap(err,"code","NoApplicableCode");
    286         printExceptionReportResponse(m,err);
     250        PythonZooReport(m,tmp->value,0);
    287251        res=-1;
    288252      }
     
    291255      char tmpS[1024];
    292256      sprintf(tmpS, "Cannot find the %s function in the %s file.\n", s->name, tmp->value);
    293       map* tmps=createMap("text",tmpS);
    294       printExceptionReportResponse(m,tmps);
     257      errorException(m,tmpS,"NoApplicableCode",NULL);
    295258      res=-1;
    296259    }
    297260  } else{
    298     char tmpS[1024];
    299     sprintf(tmpS, "Python module %s cannot be loaded.\n", tmp->value);
    300     map* tmps=createMap("text",tmpS);
    301     printExceptionReportResponse(m,tmps);
    302     if (PyErr_Occurred())
    303       PyErr_Print();
    304     PyErr_Clear();
     261    PythonZooReport(m,tmp->value,1);
    305262    res=-1;
    306263  }
     
    312269  Py_Finalize();
    313270  return res;
     271}
     272
     273void PythonZooReport(maps* m,const char* module,int load){
     274  PyObject *pName, *pModule, *pFunc;
     275  PyObject *ptype, *pvalue, *ptraceback,*pValue,*pArgs;
     276  PyErr_Fetch(&ptype, &pvalue, &ptraceback);
     277  char *pStrErrorMessage = PyString_AsString(pvalue);
     278  char *tmp0=_("Python module %s cannot be loaded. Message: %s\n");
     279 
     280  PyObject *trace=PyObject_Str(pvalue);
     281  char *pbt=NULL;
     282  if(PyString_Check(trace)){
     283    pbt=(char*)malloc((7+strlen(PyString_AsString(trace))+1)*sizeof(char));
     284    sprintf(pbt,"TRACE: %s",PyString_AsString(trace));
     285  }
     286  else
     287    fprintf(stderr,"EMPTY TRACE ?");
     288 
     289  trace=NULL;
     290 
     291  trace=PyObject_Str(ptype);
     292  if(PyString_Check(trace)){
     293    char *tpbt=zStrdup(pbt);
     294    if(pbt!=NULL)
     295      free(pbt);
     296    pbt=(char*)malloc((1+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));
     297    sprintf(pbt,"%s\n%s",tpbt,PyString_AsString(trace));
     298    free(tpbt);
     299  }
     300  else
     301    fprintf(stderr,"EMPTY TRACE ?");
     302 
     303  if(ptraceback!=NULL){
     304    char *tpbt=zStrdup(pbt);
     305    pName = PyString_FromString("traceback");
     306    pModule = PyImport_Import(pName);
     307    pArgs = PyTuple_New(1);
     308    PyTuple_SetItem(pArgs, 0, ptraceback);
     309    pFunc = PyObject_GetAttrString(pModule,"format_tb");
     310    pValue = PyObject_CallObject(pFunc, pArgs);
     311    trace=NULL;
     312    trace=PyObject_Str(pValue);
     313    if(PyString_Check(trace)){
     314      if(pbt!=NULL)
     315        free(pbt);
     316      pbt=(char*)malloc((90+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));
     317      sprintf(pbt,_("%s\nUnable to run your python process properly. Please check the following messages : %s"),tpbt,PyString_AsString(trace));
     318    }
     319    else{
     320      if(pbt!=NULL)
     321        free(pbt);
     322      pbt=(char*)malloc((90+strlen(tpbt)+strlen(PyString_AsString(trace))+1)*sizeof(char));     
     323      sprintf(pbt,_("%s \n Unable to run your python process properly. Unable to provide any futher informations."),tpbt);
     324    }
     325    free(tpbt);
     326  }
     327  if(load>0){
     328    char *tmpS=(char*)malloc((strlen(tmp0)+strlen(module)+strlen(pbt)+1)*sizeof(char));
     329    sprintf(tmpS,tmp0,module,pbt);
     330    errorException(m,tmpS,"NoApplicableCode",NULL);
     331    free(tmpS);
     332  }else
     333    errorException(m,pbt,"NoApplicableCode",NULL);
     334  free(pbt);
    314335}
    315336
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png