{"id":10579,"library":"bluebird-retry","title":"Bluebird Promise Retry Utility","description":"bluebird-retry is a utility library for Node.js and browsers that facilitates retrying an asynchronous operation until it successfully resolves. It leverages Bluebird promises for its core functionality and expects Bluebird to be provided as a peer dependency. The current stable version is 0.11.0. This package supports various retry mechanisms including regular intervals, exponential backoff with configurable limits, and an overall operation timeout. A key differentiator is its ability to conditionally retry based on a `predicate` (similar to Bluebird's filtered catch) and to explicitly stop the retry loop by throwing a `StopError`. While functional, the package appears to be in maintenance mode, with its last release (v0.11.0) occurring several years ago, and is primarily designed for CommonJS environments.","status":"maintenance","version":"0.11.0","language":"javascript","source_language":"en","source_url":"https://github.com/demmer/bluebird-retry","tags":["javascript","bluebird","promise","retry"],"install":[{"cmd":"npm install bluebird-retry","lang":"bash","label":"npm"},{"cmd":"yarn add bluebird-retry","lang":"bash","label":"yarn"},{"cmd":"pnpm add bluebird-retry","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the underlying promise implementation; required as a peer dependency since v0.6.0.","package":"bluebird","optional":false}],"imports":[{"note":"Primarily designed for CommonJS; direct ESM import might not work without bundler configuration. The `retry` function is the main export.","wrong":"import retry from 'bluebird-retry';","symbol":"retry","correct":"const retry = require('bluebird-retry');"},{"note":"StopError is a property of the main `retry` export, not a named export. It's used to gracefully exit the retry loop.","wrong":"import { StopError } from 'bluebird-retry';","symbol":"retry.StopError","correct":"const retry = require('bluebird-retry');\n// ... then later ...\nthrow new retry.StopError('message');"},{"note":"bluebird-retry depends on Bluebird. If your operation uses `Promise.resolve` or `Promise.reject`, you must ensure Bluebird is imported and available, especially in older CJS contexts. Bluebird also has an ESM export, but CJS `require` is typical for older patterns.","wrong":"import { Promise } from 'bluebird';","symbol":"Promise (from bluebird)","correct":"const Promise = require('bluebird');"}],"quickstart":{"code":"const Promise = require('bluebird');\nconst retry = require('bluebird-retry');\n\nlet count = 0;\nfunction myfunc() {\n    console.log('myfunc called ' + (++count) + ' times');\n    if (count < 3) {\n        // Simulate an asynchronous failure with a Bluebird rejection\n        return Promise.reject(new Error('fail the first two times'));\n    } else {\n        // Simulate an asynchronous success\n        return Promise.resolve('succeed the third time');\n    }\n}\n\nretry(myfunc, { max_tries: 5, interval: 500 })\n.then(function(result) {\n    console.log(result);\n})\n.catch(function(err) {\n    console.error('Operation failed completely:', err.message);\n});","lang":"javascript","description":"This example demonstrates how to use `bluebird-retry` to repeatedly execute an asynchronous function until it returns a successful promise, configured with a maximum number of attempts and a fixed interval."},"warnings":[{"fix":"Ensure `bluebird` is installed in your project: `npm install bluebird` or `yarn add bluebird`.","message":"The `bluebird` library was changed from a direct dependency to a peer dependency. Applications must now explicitly install `bluebird` alongside `bluebird-retry`.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Understand that `timeout` is an estimation for `max_tries`. For strict time limits, consider wrapping `bluebird-retry` with a separate Bluebird `Promise.delay` and `Promise.race` if fine-grained control is critical.","message":"The `timeout` option does not create a real-time timeout, but rather computes a maximum number of attempts based on the `interval` and `backoff` options. If both `timeout` and `max_tries` are specified, the limit that comes first will apply.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"To throw the last encountered error instance instead of a timeout error, set the `throw_original` option to `true`. Alternatively, use the `predicate` option to filter which errors cause a retry.","message":"By default, `bluebird-retry` absorbs all intermediate rejection messages, and will only propagate the final error if the operation ultimately times out or reaches `max_tries`. This can make debugging initial failures difficult.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"No direct fix needed as it's an internal implementation detail, but be aware that if you're writing new code, using standard Bluebird or native promise methods is generally preferred.","message":"The package uses `.try` and `.catch` aliases (`.attempt` and `.caught` respectively) for older browser support. While functionally equivalent in Bluebird, modern Bluebird versions and native Promises prefer `.try` (or direct `try/catch` with `async/await`) and `.catch`.","severity":"deprecated","affected_versions":">=0.6.0"},{"fix":"For new applications, consider using native `async/await` with a custom retry loop or a more modern retry library that explicitly supports `async/await` and ESM. If using `bluebird-retry`, stick to its documented CommonJS usage.","message":"As a package in maintenance mode (last update several years ago), it may not fully leverage modern JavaScript features like `async/await` directly without explicit Bluebird promisification, nor is it optimized for ESM environments without transpilation or bundler configuration.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Increase the `max_tries` option, or adjust `interval` and `backoff` to allow more attempts within the `timeout` period. Alternatively, debug the underlying function to understand why it's consistently failing and fix it.","cause":"The retry operation exhausted its maximum number of attempts (`max_tries`) or exceeded its calculated `timeout` duration before the wrapped function succeeded.","error":"Error: operation timed out"},{"fix":"Ensure `bluebird` is installed (`npm install bluebird`) and imported at the top of your file: `const Promise = require('bluebird');`.","cause":"The `bluebird` library, which `bluebird-retry` depends on, has not been properly imported or is not available in the global scope/module context.","error":"Promise is not defined"},{"fix":"Ensure you are importing `bluebird-retry` using `const retry = require('bluebird-retry');` and then referencing `retry.StopError` correctly. Do not try to destructure `StopError` directly from the package import.","cause":"You are attempting to use `retry.StopError` but `retry` was not correctly imported or is not the object containing the `StopError` class.","error":"TypeError: retry.StopError is not a constructor"}],"ecosystem":"npm"}