{"record":{"id":"e682bcf2829d7d3f","repo":"hashicorp/vagrant","slug":"a-script-exited-with-an-unacceptable-exit-code-c","errorCode":null,"errorMessage":"A script exited with an unacceptable exit code %{code}.","messagePattern":"A script exited with an unacceptable exit code %(.+?)\\.","errorType":"exception","errorClass":"Vagrant::Errors::TriggersBadExitCodes","httpStatus":null,"severity":"error","filePath":"lib/vagrant/plugin/v2/trigger.rb","lineNumber":280,"sourceCode":"            else\n              exec_method = Vagrant::Util::PowerShell.method(:execute)\n            end\n          end\n\n          begin\n            result = exec_method.call(*cmd, :notify => [:stdout, :stderr]) do |type,data|\n              options = {}\n              case type\n              when :stdout\n                options[:color] = :green if !config.keep_color\n              when :stderr\n                options[:color] = :red if !config.keep_color\n              end\n\n              @ui.detail(data, **options)\n            end\n            if !exit_codes.include?(result.exit_code)\n              raise Errors::TriggersBadExitCodes,\n                code: result.exit_code\n            end\n          rescue => e\n            @ui.error(I18n.t(\"vagrant.errors.triggers_run_fail\"))\n            @ui.error(e.message)\n\n            if on_error == :halt\n              @logger.debug(\"Trigger run encountered an error. Halting on error...\")\n              raise e\n            else\n              @logger.debug(\"Trigger run encountered an error. Continuing on anyway...\")\n              @ui.warn(I18n.t(\"vagrant.trigger.on_error_continue\"))\n            end\n          end\n        end\n\n        # Runs a script on the guest\n        #","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/plugin/v2/trigger.rb#L262-L298","documentation":"A trigger's `run` script finished with an exit code not in the trigger's allowed exit_codes list (default [0]), so run_script raised TriggersBadExitCodes (lib/vagrant/plugin/v2/trigger.rb:280). With the default `on_error: :halt` the error is re-raised after the script's output, aborting the vagrant command; with `on_error: :continue` Vagrant logs the failure and continues instead. %{code} is the script's actual exit status.","triggerScenarios":"A Vagrantfile trigger like `trigger.after :up do |t| t.run = {inline: \"./script.sh\"} end` where script.sh exits 1 — including the shell's 127 for a missing script and 126 for a non-executable file — and the code is not whitelisted via t.exit_codes.","commonSituations":"Scripts that use non-zero exits for warnings (grep-style); forgetting chmod +x; paths assumed wrong relative to the project root; scripts depending on env vars absent in the trigger context; Windows batch exit codes.","solutions":["Run the script manually the way Vagrant does (bash -c from the project root) and fix whatever makes it exit non-zero","If the non-zero code is expected, whitelist it on the trigger: t.exit_codes = [0, 1]","If failure is acceptable for this workflow, set t.on_error = :continue","Debug with VAGRANT_LOG=debug to see the exact executed command and its output"],"exampleFix":"# before\ntrigger.after :up do |t|\n  t.run = { inline: \"./check.sh\" }  # check.sh exits 1 on warnings\nend\n\n# after\ntrigger.after :up do |t|\n  t.run = { inline: \"./check.sh\" }\n  t.exit_codes = [0, 1]   # 1 means warning, not failure\nend","handlingStrategy":"validation","validationCode":"ok = system(\"bash\", \"-c\", \"./check.sh\", out: File::NULL, err: File::NULL)\ncode = $?.exitstatus\nabort \"trigger script exits #{code}; whitelist it via exit_codes or fix the script\" unless code.zero?","typeGuard":null,"tryCatchPattern":"begin\n  env.cli(:up)\nrescue Vagrant::Errors::TriggersBadExitCodes => e\n  warn \"trigger script failed with exit code #{e.extra_data[:code]}\"\nend","preventionTips":["Make trigger scripts exit 0 on success; report warnings on stderr instead of via exit codes","chmod +x local scripts and use paths relative to the project root","Whitelist every intentional non-zero code with t.exit_codes = [0, N]","Decide explicitly per trigger whether on_error should :halt or :continue"],"tags":["triggers","exit-code","shell","scripts"],"backgroundTag":"nonzero-exit-code","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}