nickva commented on PR #5431:
URL: https://github.com/apache/couchdb/pull/5431#issuecomment-2660206501

   Playing around with an older python view script:
   
   ```python
   #!/usr/bin/env python3
   #
   # pip install CouchDB
   #
   # ./dev/run --admin=adm:pass -n 1
   # ./view_with_error.py
   
   import sys, couchdb
   
   URL='http://adm:pass@localhost:15984'
   DB = 'db'
   
   MAP_FUN = '''
   function(doc){
     try{
       emit(doc.data.v, doc._id)
     } catch(e) {
       emit(["error", doc._id], e)
     }
   }'''
   
   def add_view(db, docid):
       db[docid] = {
           "views": {
               "v1": {"map": MAP_FUN}
           }
       }
   
   def main(dbname):
       s = couchdb.Server(URL)
       if dbname in set(s):
           s.delete(dbname)
       db = s.create(dbname)
       add_view(db, docid='_design/ddoc')
       db.update([
           {'_id':'doc1', 'data':{'v':42}},
           {'_id':'doc2', 'sorry':'no_data_here'},
           {'_id':'doc3', 'data':{'v':43}},
       ])
       for r in db.view('ddoc/v1'):
           print(r)
   
   if __name__=='__main__':
       main(DB)
   ```
   
   ```
   ./view_with_error.py
   <Row id='doc1', key=42, value='doc1'>
   <Row id='doc3', key=43, value='doc3'>
   <Row id='doc2', key=['error', 'doc2'], value={'error': 'TypeError', 
'message': 'doc.data is undefined'}>
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to