educoder/sail.js.wallcology — Issue #58: Agent throws errors in log file
Author: mackrauss
Created: 2011-11-09 22:22:29+00:00
State: open
Labels: bug

I see this in the log file

2011-11-09T17:11:50.%L [wallcology-julia-fall2011@conference.proto.encorelab.org/Archivist] [INFO] observation id in stanza 1bymvwhgfk03do2px698v3m823tm71bls
2011-11-09T17:11:50.%L [wallcology-julia-fall2011@conference.proto.encorelab.org/Archivist] [INFO] No observation found for id: 1bymvwhgfk03do2px698v3m823tm71bls
2011-11-09T17:11:50.%L [wallcology-julia-fall2011@conference.proto.encorelab.org/Archivist] [FATAL] undefined method `[]=' for nil:NilClass
./archivist.rb:47:in `behaviour'

caused by line 47 in agent.rb
observationFromDb[k] = v

In this loop

observation.each_pair do |k,v|
observationFromDb[k] = v
end

observationFromDb might be empty if nothing is found it Database. Maybe we need to make sure that this loop is only
perfomed if observationFromDb != nil
and if it is nil copy observation (from XMPP) into observationFromDb

like so:

if observationFromDb != nil
log "Observation hash for id #{observation['_id']} from mongo db: #{observationFromDb}"
# TODO iterate over observation and copy all fields to observationFromDb then store observationFromDb
observation.each_pair do |k,v|
observationFromDb[k] = v
end
else
log "No observation found for id: #{observation['_id']}"
# no observation returned from db so copy observation into observationDB
observationFromDb = observation
end