maxdemarzi / neography

A thin Ruby wrapper to the Neo4j Rest API
MIT License
602 stars 135 forks source link

java.lang.NullPointerException: Cannot invoke method out() on null object #180

Closed BenMorganIO closed 9 years ago

BenMorganIO commented 10 years ago

Not sure if this was me, the gremlin plugin, or neography, but I'm currently receiving this error while using neoid:

javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method out() on null object

The stack trace I currently have is not too helpful. I will be cross posting this issue on Neography and Neoid to help find the source of this error.

Neography::BadInputException - javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method out() on null object:
  neography (1.5.1) lib/neography/connection.rb:245:in `raise_errors'
  neography (1.5.1) lib/neography/connection.rb:217:in `handle_4xx_500_response'
  neography (1.5.1) lib/neography/connection.rb:188:in `return_result'
  neography (1.5.1) lib/neography/connection.rb:159:in `evaluate_response'
  neography (1.5.1) lib/neography/connection.rb:71:in `block (3 levels) in <class:Connection>'
  neography (1.5.1) lib/neography/connection.rb:84:in `log'
  neography (1.5.1) lib/neography/connection.rb:62:in `block (2 levels) in <class:Connection>'
  neography (1.5.1) lib/neography/rest/gremlin.rb:14:in `execute_script'
  neoid (0.1.2) lib/neoid.rb:113:in `execute_script_or_add_to_batch'
  neoid (0.1.2) lib/neoid/node.rb:66:in `neo_subref_node'
  neoid (0.1.2) lib/neoid/node.rb:127:in `_neo_save'
  neoid (0.1.2) lib/neoid/model_additions.rb:56:in `neo_save'
  neoid (0.1.2) lib/neoid/model_additions.rb:50:in `neo_save_after_model_save'
  activesupport (4.1.1) lib/active_support/callbacks.rb:424:in `block in make_lambda'
  activesupport (4.1.1) lib/active_support/callbacks.rb:221:in `block in halting_and_conditional'
  activesupport (4.1.1) lib/active_support/callbacks.rb:86:in `run_callbacks'
  activerecord (4.1.1) lib/active_record/callbacks.rb:302:in `create_or_update'
  activerecord (4.1.1) lib/active_record/persistence.rb:103:in `save'
  activerecord (4.1.1) lib/active_record/validations.rb:51:in `save'
  activerecord (4.1.1) lib/active_record/attribute_methods/dirty.rb:21:in `save'
  activerecord (4.1.1) lib/active_record/transactions.rb:268:in `block (2 levels) in save'
  activerecord (4.1.1) lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
  activerecord (4.1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
  activerecord (4.1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
  activerecord (4.1.1) lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
  activerecord (4.1.1) lib/active_record/transactions.rb:208:in `transaction'
  activerecord (4.1.1) lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
  activerecord (4.1.1) lib/active_record/transactions.rb:268:in `block in save'
  activerecord (4.1.1) lib/active_record/transactions.rb:283:in `rollback_active_record_state!'
  activerecord (4.1.1) lib/active_record/transactions.rb:267:in `save'
  devise (3.2.4) lib/devise/models/trackable.rb:30:in `update_tracked_fields!'
  devise (3.2.4) lib/devise/hooks/trackable.rb:7:in `block in <top (required)>'
  warden (1.2.3) lib/warden/hooks.rb:14:in `block in _run_callbacks'
  warden (1.2.3) lib/warden/hooks.rb:9:in `_run_callbacks'
  warden (1.2.3) lib/warden/manager.rb:53:in `_run_callbacks'
  warden (1.2.3) lib/warden/proxy.rb:179:in `set_user'
  warden (1.2.3) lib/warden/proxy.rb:323:in `_perform_authentication'
  warden (1.2.3) lib/warden/proxy.rb:127:in `authenticate!'
  devise (3.2.4) app/controllers/devise/sessions_controller.rb:15:in `create'
  actionpack (4.1.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.1.1) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.1.1) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
  activesupport (4.1.1) lib/active_support/callbacks.rb:229:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:229:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:229:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.1) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
  activesupport (4.1.1) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
  activesupport (4.1.1) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
  activesupport (4.1.1) lib/active_support/callbacks.rb:86:in `run_callbacks'
  actionpack (4.1.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.1.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.1.1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.1.1) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.1) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.1.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.1.1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.1.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.1.1) lib/abstract_controller/base.rb:136:in `process'
  actionview (4.1.1) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.1.1) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.1.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.1.1) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.1.1) lib/action_dispatch/routing/mapper.rb:45:in `call'
  actionpack (4.1.1) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.1.1) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:676:in `call'
  meta_request (0.3.0) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
  rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.3.0) lib/meta_request/middlewares/headers.rb:16:in `call'
  meta_request (0.3.0) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
  neoid (0.1.2) lib/neoid/middleware.rb:10:in `call'
  newrelic_rpm (3.7.3.204) lib/new_relic/rack/error_collector.rb:55:in `call'
  newrelic_rpm (3.7.3.204) lib/new_relic/rack/agent_hooks.rb:32:in `call'
  newrelic_rpm (3.7.3.204) lib/new_relic/rack/browser_monitoring.rb:27:in `call'
  newrelic_rpm (3.7.3.204) lib/new_relic/rack/developer_mode.rb:45:in `call'
  request_store (1.0.5) lib/request_store/middleware.rb:9:in `call'
  rack-livereload (0.3.15) lib/rack/livereload.rb:23:in `_call'
  rack-livereload (0.3.15) lib/rack/livereload.rb:14:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/flash.rb:254:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.1.1) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
  activerecord (4.1.1) lib/active_record/migration.rb:380:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.1.1) lib/active_support/callbacks.rb:82:in `run_callbacks'
  actionpack (4.1.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:143:in `pass'
  rack-cache (1.2) lib/rack/cache/context.rb:155:in `invalidate'
  rack-cache (1.2) lib/rack/cache/context.rb:71:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.1) lib/rails/engine.rb:514:in `call'
  railties (4.1.1) lib/rails/application.rb:144:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:143:in `pass'
  rack-cache (1.2) lib/rack/cache/context.rb:155:in `invalidate'
  rack-cache (1.2) lib/rack/cache/context.rb:71:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  thin (1.6.2) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.6.2) lib/thin/connection.rb:84:in `pre_process'
  thin (1.6.2) lib/thin/connection.rb:53:in `process'
  thin (1.6.2) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
  thin (1.6.2) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.2) lib/thin/server.rb:162:in `start'
  rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
  rack (1.5.2) lib/rack/server.rb:264:in `start'
  railties (4.1.1) lib/rails/commands/server.rb:69:in `start'
  zeus (0.15.1) lib/zeus/rails.rb:160:in `server'
  zeus (0.15.1) lib/zeus.rb:148:in `block in command'
  zeus (0.15.1) lib/zeus.rb:135:in `command'
  zeus (0.15.1) lib/zeus.rb:50:in `go'
  -e:1:in `<main>'

Expected Result: My web page loads in Rails. Given Result: I am given this error.

I apologize for the lack of information, but I'm not too sure what's caused this.

maxdemarzi commented 10 years ago

The error:

Neography::BadInputException - javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method out() on null object:

Is telling us that NeoId created a gremlin script that did a traversal node.out() but the node in question is null. So enable logging to try to capture the gremlin script.

Set config.log_enabled = true

see https://github.com/maxdemarzi/neography/wiki/Configuration-and-initialization for details

BenMorganIO commented 10 years ago

Within 01_neoid.rb this is what I have done:

require('neography') unless defined?(Neography)

ENV["NEO4J_URL"] ||= "http://localhost:7474"

uri = URI.parse(ENV["NEO4J_URL"])

$neo = Neography::Rest.new(uri.to_s)

Neography.configure do |config|
  config.server = uri.host
  config.port = uri.port

  if uri.user && uri.password
    config.authentication = 'basic'
    config.username = uri.user
    config.password = uri.password
  end

  config.log_file             = "log/neography.log"
  config.gremlin_path         = "http://localhost:7474/db/data/ext/GremlinPlugin/graphdb/execute_script"
  config.log_enabled          = true
end

Neoid.db = $neo

Neoid.configure do |c|
  c.enable_subrefs = true
end

I can't get a log/neography.log to appear and there's nothing new appearing in the stack traces. I'll keep tinkering.

BenMorganIO commented 10 years ago

This is what I was doing:

I was logging in as a user on my application. I have devise installed. This was the user model:

class User < ActiveRecord::Base
  include Neoid::Node

  neoidable do |c|
    c.field :email
  end

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :confirmable, :lockable, :timeoutable

  include Gravtastic
  gravtastic

  validates_presence_of :first_name, :last_name

  def full_name
    first_name + ' ' + last_name
  end

  def member_since
    created_at.strftime('%B %Y')
  end
end

When I remove the neoidable block, it works and log/neography.log appears.

maxdemarzi commented 10 years ago

Neoid.configure do |c|

should Neoid create sub-reference from the ref node (id#0) to every node-model? default: true

c.enable_subrefs = false end

BenMorganIO commented 10 years ago

I'm making progress. Thanks @maxdemarzi. My next error is:

NoMethodError: undefined method `dump' for #<Excon::Response:0x007ff3af465280>
from /Users/benmorgan/.rvm/gems/ruby-2.1.2/gems/neography-1.5.1/lib/neography/connection.rb:216:in `handle_4xx_500_response'

I'll hunt around and get to the bottom of this. I want to see more Rails projects using Neoid/Neography/Neo4j. Will post if it is out of my limits.