{"record":{"id":"8167734f690120c1","repo":"github/scientist","slug":"experiment-name-missing-name-behavior","errorCode":null,"errorMessage":"#{experiment.name} missing #{name} behavior","messagePattern":"#(.+?) missing #(.+?) behavior","errorType":"exception","errorClass":"Scientist::BehaviorMissing","httpStatus":null,"severity":"error","filePath":"lib/scientist/experiment.rb","lineNumber":230,"sourceCode":"  # Called when an exception is raised while running an internal operation,\n  # like :publish. Override this method to track these exceptions. The\n  # default implementation re-raises the exception.\n  def raised(operation, error)\n    raise error\n  end\n\n  # Internal: Run all the behaviors for this experiment, observing each and\n  # publishing the results. Return the result of the named behavior, default\n  # \"control\".\n  def run(name = nil)\n    behaviors.freeze\n    context.freeze\n\n    name = (name || \"control\").to_s\n    block = behaviors[name]\n\n    if block.nil?\n      raise Scientist::BehaviorMissing.new(self, name)\n    end\n\n    unless should_experiment_run?\n      return block.call\n    end\n\n    if @_scientist_before_run\n      @_scientist_before_run.call\n    end\n\n    result = generate_result(name)\n\n    if @_scientist_after_run\n      @_scientist_after_run.call(result)\n    end\n\n    begin\n      publish(result)","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/github/scientist/blob/504a396e987f655a21c6bf2ed57935aadaa40859/lib/scientist/experiment.rb#L212-L248","documentation":"Scientist::BehaviorMissing is raised by Experiment#run when the behavior name passed to `run(name)` (defaulting to \"control\") is not present in the experiment's registered behaviors hash. An experiment can only run a behavior registered via `use`/`try`; this error guards against running an experiment whose required control (or named) behavior was never defined.","triggerScenarios":"Calling `experiment.run` when no `use`/control behavior was registered, or calling `experiment.run(\"candidate\")` where no `try(\"candidate\")` with that name was registered. Also triggered by a name typo/mismatch between `run(name)` and `try(name)`, or by registering behaviors on a different experiment instance (behaviors are per-instance and frozen at run time).","commonSituations":"Refactors that rename a candidate but forget to update the `run` call; experiments where `try`/`use` is called conditionally so the control is never registered on some code paths; copy-pasted experiment definitions missing the `use` block.","solutions":["Register the control behavior with `use { ... }` before calling `run`.","Make the name passed to `run(name)` exactly match a name passed to `try(name)` (both are to_s'd, so 'x' and :x are equivalent).","Register behaviors unconditionally on every code path that reaches `run`, or check that the behavior exists before running.","Verify you are running the same experiment instance on which the behaviors were registered."],"exampleFix":"# before\nexperiment = MyExperiment.new\nexperiment.try(\"new_code\") { compute_v2 }\nexperiment.run # raises BehaviorMissing (no control)\n\n# after\nexperiment = MyExperiment.new\nexperiment.use { compute_v1 }\nexperiment.try(\"new_code\") { compute_v2 }\nexperiment.run # returns control value","handlingStrategy":"validation","validationCode":"def behavior_registered?(exp, name = \"control\")\n  exp.send(:behaviors).key?(name.to_s)\nend\nraise \"missing control behavior\" unless behavior_registered?(experiment)","typeGuard":"def behavior_registered?(exp, name = \"control\")\n  exp.respond_to?(:run) && exp.send(:behaviors).key?(name.to_s)\nrescue NoMethodError\n  false\nend","tryCatchPattern":"begin\n  result = experiment.run(\"control\")\nrescue Scientist::BehaviorMissing => e\n  logger.warn(\"scientist behavior missing: #{e.message}\")\n  fallback_compute\nend","preventionTips":["Always call `use` (control) before `run`, unconditionally on every code path.","Match `run(name)` arguments exactly to a `try(name)` registration; use string names consistently.","Keep behavior registration together in one setup method so omissions are visible in review.","Add a test asserting every experiment registers its control before running."],"tags":["ruby","scientist","behavior-missing","experiment-design"],"backgroundTag":"missing-required-argument","analyzedSha":"504a396e987f655a21c6bf2ed57935aadaa40859","analyzedAt":"2026-09-13T22:55:19.059Z","contentChangedAt":"2026-09-13T22:55:19.059Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}