important-leather-28796
10/08/2025, 11:28 AMRangeError: Invalid string length?important-leather-28796
10/08/2025, 11:32 AMimport { execSync } from 'node:child_process'
import { RunError } from '@pulumi/pulumi'
function enforceServiceAccount(allowedIdentity: 'inf' | 'app'): void {
const currentAccount = execSync('gcloud config get-value account 2>/dev/null', {
encoding: 'utf-8',
}).trim()
// Check if current account contains the disallowed identity
const disallowedIdentity = allowedIdentity === 'inf' ? 'app' : 'inf'
if (currentAccount.includes(`${disallowedIdentity}-`)) {
// Log detailed instructions to console
console.error(`\n❌ This stack requires the "${allowedIdentity}" service account.`)
console.error(`Current: ${currentAccount}`)
console.error(`\nActivate the correct account:`)
console.error(` cd cloud/identity && yarn gcpActivate ${allowedIdentity}\n`)
// Throw a concise RunError for Pulumi
throw new RunError(
`Wrong service account: found "${disallowedIdentity}" but need "${allowedIdentity}".`,
)
}
// Optionally verify the correct account is active
if (!currentAccount.includes(`${allowedIdentity}-`)) {
console.warn(
`\n⚠️ WARNING: Expected "${allowedIdentity}" service account but found: ${currentAccount}`,
)
console.warn(`If this is not a service account, activate the "${allowedIdentity}" account:`)
console.warn(` cd cloud/identity && yarn gcpActivate ${allowedIdentity}\n`)
}
}
// Enforce that this stack runs with the 'app' service account, not 'inf'
enforceServiceAccount('app')
The preview result is desirable (in stack), but without the stack trace:
~/p/a/c/storage ❯❯❯ pulumi preview ✘ 255
Previewing update (alienfast/green)
View in Browser (Ctrl+O): <https://app.pulumi.com/alienfast/storage/green/previews/fc957836-2134-439c-8a6f-6d3db66c1d62>
Type Name Plan Info
+ pulumi:pulumi:Stack storage-green create 3 errors; 6 messages
Diagnostics:
pulumi:pulumi:Stack (storage-green):
06:22:00 debug loadProjectEnv Loading /Users/kross/projects/archetype/.env
[dotenv@17.2.3] injecting env (14) from ../../.env -- tip: 👥 sync secrets across teammates & machines: <https://dotenvx.com/ops>
❌ This stack requires the "app" service account.
Current: <mailto:inf-green@af-archetype.iam.gserviceaccount.com|inf-green@af-archetype.iam.gserviceaccount.com>
Activate the correct account:
cd cloud/identity && yarn gcpActivate app
error: Wrong service account: found "inf" but need "app".
error: Running program '/Users/kross/projects/archetype/cloud/storage/src/index.ts' failed with an unhandled exception:
RangeError: Invalid string length
at markNodeModules (node:internal/util/inspect:1601:21)
at formatError (node:internal/util/inspect:1691:18)
at formatRaw (node:internal/util/inspect:1084:14)
at formatValue (node:internal/util/inspect:932:10)
at Object.inspect (node:internal/util/inspect:409:10)
at Object.defaultErrorMessage (/Users/kross/projects/archetype/node_modules/@pulumi/cmd/run/error.ts:28:21)
at process.uncaughtHandler (/Users/kross/projects/archetype/node_modules/@pulumi/cmd/run/run.ts:449:41)
at process.emit (node:events:520:35)
at process.emit (/Users/kross/projects/archetype/node_modules/source-map-support/source-map-support.js:516:21)
at process.emit.sharedData.processEmitHook.installedValue [as emit] (/Users/kross/projects/archetype/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
error: an unhandled error occurred: Program exited with non-zero exit code: 1
Resources:
+ 1 to create
The real problem is that if I want to reuse this function across stacks and put it in my shared common dir (with other shared resources that work), I get NO messages, just
~/p/a/c/storage ❯❯❯ pulumi preview ✘ 255
Previewing update (alienfast/green)
View in Browser (Ctrl+O): <https://app.pulumi.com/alienfast/storage/green/previews/30e2cca5-65f8-406b-8b53-29453cad9580>
Type Name Plan Info
+ pulumi:pulumi:Stack storage-green create 2 errors
Diagnostics:
pulumi:pulumi:Stack (storage-green):
error: Running program '/Users/kross/projects/archetype/cloud/storage/src/index.ts' failed with an unhandled exception:
RangeError: Invalid string length
at markNodeModules (node:internal/util/inspect:1601:21)
at formatError (node:internal/util/inspect:1691:18)
at formatRaw (node:internal/util/inspect:1084:14)
at formatValue (node:internal/util/inspect:932:10)
at Object.inspect (node:internal/util/inspect:409:10)
at Object.defaultErrorMessage (/Users/kross/projects/archetype/node_modules/@pulumi/cmd/run/error.ts:28:21)
at process.uncaughtHandler (/Users/kross/projects/archetype/node_modules/@pulumi/cmd/run/run.ts:445:3)
at process.emit (node:events:520:35)
at process.emit (/Users/kross/projects/archetype/node_modules/source-map-support/source-map-support.js:516:21)
at process.emit.sharedData.processEmitHook.installedValue [as emit] (/Users/kross/projects/archetype/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
error: an unhandled error occurred: Program exited with non-zero exit code: 1
TL;DR how do I raise an error properly, get the messages printed to the console, and not see an ugly stack trace for RangeError: Invalid string length?important-leather-28796
10/08/2025, 11:34 AMimportant-leather-28796
10/08/2025, 11:44 AMlemon-scooter-94063
10/08/2025, 2:08 PMprocess.exit(1) instead of the throw new runError will work better. It won't output the stack trace and I think it will be handled better when used as a shared module. I haven't tested it myself but I believe it should workimportant-leather-28796
10/08/2025, 2:36 PMimportant-leather-28796
10/08/2025, 2:38 PM~/p/a/c/storage ❯❯❯ pulumi preview
Previewing update (alienfast/green)
View in Browser (Ctrl+O): <https://app.pulumi.com/alienfast/storage/green/previews/d34df4f3-848a-47ee-8705-4f4bdb85bc07>
Type Name Plan Info
pulumi:pulumi:Stack storage-green 2 errors
Diagnostics:
pulumi:pulumi:Stack (storage-green):
error: Running program '/Users/kross/projects/archetype/cloud/storage/src/index.ts' failed with an unhandled exception:
RangeError: Invalid string length
at markNodeModules (node:internal/util/inspect:1601:21)
at formatError (node:internal/util/inspect:1691:18)
at formatRaw (node:internal/util/inspect:1084:14)
at formatValue (node:internal/util/inspect:932:10)
at Object.inspect (node:internal/util/inspect:409:10)
at Object.defaultErrorMessage (/Users/kross/projects/archetype/node_modules/@pulumi/cmd/run/error.ts:28:21)
at process.uncaughtHandler (/Users/kross/projects/archetype/node_modules/@pulumi/cmd/run/run.ts:445:3)
at process.emit (node:events:520:35)
at process.emit (/Users/kross/projects/archetype/node_modules/source-map-support/source-map-support.js:516:21)
at process.emit.sharedData.processEmitHook.installedValue [as emit] (/Users/kross/projects/archetype/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
error: an unhandled error occurred: Program exited with non-zero exit code: 1
Resources:
1 unchangedlemon-scooter-94063
10/08/2025, 2:55 PMthrow new Error instead of the throw new RunError ? I'm curious, when you ran it locally, did process.exit(1) exit cleanly and only output your error message minus the stack trace?important-leather-28796
10/08/2025, 2:56 PMthrow new Error, same result. process.exit output is above, no error plus stack tracelemon-scooter-94063
10/08/2025, 2:57 PMimportant-leather-28796
10/08/2025, 2:58 PMprocess.exit(1) is clean and prints the error. Similar to the github issue I linked, this isn’t very useful because we want to use this in 7 stacks.lemon-scooter-94063
10/08/2025, 3:10 PMexport step for that function. Was it just not in your screenshot or is that missing?important-leather-28796
10/08/2025, 3:10 PMimportant-leather-28796
10/08/2025, 3:11 PMimportant-leather-28796
10/08/2025, 3:12 PMimportant-leather-28796
10/08/2025, 3:13 PMlemon-scooter-94063
10/08/2025, 3:18 PMimportant-leather-28796
10/08/2025, 3:19 PMimportant-leather-28796
10/08/2025, 3:21 PMlemon-scooter-94063
10/08/2025, 3:27 PM