Skip to content

fix: instantiate Result with new in resultWrapper#390

Open
achromik wants to merge 1 commit into
contentstack:masterfrom
achromik:fix/result-class-call-without-new
Open

fix: instantiate Result with new in resultWrapper#390
achromik wants to merge 1 commit into
contentstack:masterfrom
achromik:fix/result-class-call-without-new

Conversation

@achromik

@achromik achromik commented Jun 11, 2026

Copy link
Copy Markdown

Problem

Since 3.18.0 (taxonomy support release), src/core/modules/result.js exports Result as an ES class — previously it exported a factory function (module.exports = function (object) { return new Result(object); }). However, resultWrapper() in src/core/lib/utils.js still invokes Result(...) as a plain function in 5 places.

Any success response going through resultWrapper — e.g. Stack.ContentType(...).Entry(uid).fetch() without .toJSON() — throws:

TypeError: Cannot call a class as a function

This is a regression introduced in 3.18.0 — versions <= 3.17.2 are unaffected.

Repro (offline, >= 3.24.0 where the SDK uses global fetch)

global.fetch = async () =>
  new Response(JSON.stringify({ entry: { uid: 'u1', title: 't', locale: 'en', _version: 1 } }),
    { status: 200, headers: { 'content-type': 'application/json' } });

const ContentStack = require('contentstack');
const stack = new ContentStack.Stack({ api_key: 'k', delivery_token: 't', environment: 'live' });
await stack.ContentType('list').Entry('u1').only('items', ['uid']).fetch();
// throws TypeError: Cannot call a class as a function
// after this fix: resolves correctly

For 3.18.0–3.23.x the same failure reproduces with node-fetch stubbed instead of global.fetch (those versions use the node-fetch dependency).

Fix

Add the missing new keyword at the 5 Result(...) call sites in resultWrapper().

Verified by applying the equivalent change to the built dist/node/contentstack.js and re-running the repro above — the entry resolves correctly.

@achromik achromik requested a review from a team as a code owner June 11, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant