Balena env rm: Database error

Original Github issue: https://github.com/balena-io/open-balena/issues/61

As of right now, deleting environment variables on openBalena is not possible due to a BalenaRequestError: Request error: Database error. This happens on device and application variables.

$ balena -v
11.7.3

$ balena env add BALENA_SUPERVISOR_LOCAL_MODE 1 --device 0a160ca


$ balena envs --device 0a160ca --config
ID NAME                         VALUE
1  BALENA_SUPERVISOR_LOCAL_MODE 1

$ balena env rm BALENA_SUPERVISOR_LOCAL_MODE --device 0a160ca
? Are you sure you want to delete the environment variable? Yes
BalenaRequestError: Request error: Database error
    at C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\balena-request\build\request.js:197:17
    at tryCatcher (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\promise.js:517:31)
    at Promise._settlePromise (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\promise.js:574:18)
    at Promise._settlePromise0 (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\promise.js:619:10)
    at Promise._settlePromises (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\promise.js:699:18)
    at _drainQueueStep (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\async.js:138:12)
    at _drainQueue (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\async.js:131:9)
    at Async._drainQueues (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\async.js:17:14)
    at processImmediate (internal/timers.js:439:21)
    at process.topLevelDomainCallback (domain.js:126:23)

If you need help, don't hesitate in contacting our support forums at
https://forums.balena.io

For bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/

(node:17136) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated

@dfunckt Any idea what might be causing this? I am still getting this error, even after upgrading balena-cli to 11.7.5:

$ balena env add TEST_ENV 1 --device 59525b1

$ balena envs --device 59525b1
ID NAME     VALUE
6  TEST_ENV 1

$ balena env rm TEST_ENV --device 59525b1
? Are you sure you want to delete the environment variable? Yes
BalenaRequestError: Request error: Database error

Additional information may be available by setting a DEBUG=1 environment
variable: "set DEBUG=1" on a Windows command prompt, or "export DEBUG=1"
on Linux or macOS.

If you need help, dont hesitate in contacting our support forums at
https://forums.balena.io

For bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/

(node:9884) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated

$ balena envs --device 59525b1
ID NAME     VALUE
6  TEST_ENV 1

Hi, is the device in local mode? Also, could you post the output of DEBUG=1 balena env rm TEST_ENV --device 59525b1 ?

This one is not. Since my original post I have made a new openBalena install and haven’t set any device to local mode.

$ DEBUG=1 balena env rm TEST_ENV --device 59525b1 
Debug: original argv0="C:\Program Files\nodejs\node.exe" argv=[C:\Program Files\nodejs\node.exe,C:\Program Files\nodejs\node_modules\balena-cli\bin\balena,env,rm,TEST_ENV,--device,59525b1] length=7
? Are you sure you want to delete the environment variable? Yes
BalenaRequestError: Request error: Database error
    at C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\balena-request\build\request.js:197:17
    at tryCatcher (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\promise.js:517:31)
    at Promise._settlePromise (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\promise.js:574:18)
    at Promise._settlePromise0 (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\promise.js:619:10)
    at Promise._settlePromises (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\promise.js:699:18)
    at _drainQueueStep (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\async.js:138:12)
    at _drainQueue (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\async.js:131:9)
    at Async._drainQueues (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\ProgramData\nvm\v12.7.0\node_modules\balena-cli\node_modules\bluebird\js\release\async.js:17:14)
    at processImmediate (internal/timers.js:439:21)
    at process.topLevelDomainCallback (domain.js:126:23)

If you need help, dont hesitate in contacting our support forums at    
https://forums.balena.io

For bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/    
(node:15440) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated

$

Thanks for the information. What OS version is the device running and what device is it? I will try and replicate the bug on my local machine

I am testing using many Raspberry Pi 3B+.
os_version: balenaOS 2.38.0+rev1
os_variant: dev

I just tried with another device using the prod os_variant, but I get the same error.

Got some more! I managed to go through the large amount of logs openBalena produces and found this happening when running the balena env rm command :

Aug 06 15:31:48 7658c5fe8305 api[1469]: Parsing DELETE /resin/application_environment_variable(%27TEST_ENV%27)
Aug 06 15:31:48 7658c5fe8305 api[1469]: Running DELETE /resin/application_environment_variable(%27TEST_ENV%27)
Aug 06 15:31:48 7658c5fe8305 api[1469]: SELECT "application environment variable"."id"
Aug 06 15:31:48 7658c5fe8305 api[1469]: FROM "application environment variable"
Aug 06 15:31:48 7658c5fe8305 api[1469]: WHERE "application environment variable"."id" = $1 [ 'TEST_ENV' ]
Aug 06 15:31:48 7658c5fe8305 api[1469]: Error building the application_environment_variable filter invalid input syntax for integer: "TEST_ENV" DatabaseError: invalid input syntax for integer: "TEST_ENV"
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at wrapDatabaseError (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:41:15)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at PostgresTx.executeSql (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:143:19)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at abstract_sql_1.getAndCheckBindValues.then.values (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:926:19)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runQuery (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:922:68)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at doRunQuery (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:647:40)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at permissions.addPermissions.then (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:649:24)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Holder$2._callFunction (<anonymous>:19:29)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at uriParser.parseOData.then.request (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:643:57)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Object.exports.getAffectedIds.Promise.method (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:630:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Object.exports.getCurrentRequestAffectedIds.args [as getCurrentRequestAffectedIds] (/usr/src/app/src/platform/index.ts:90:62)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at addEnvHooks (/usr/src/app/src/hooks/resources/envvars.ts:118:23)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Hook.preRunHook [as hookFn] (/usr/src/app/src/hooks/resources/envvars.ts:24:32)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.try (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/hooks.js:12:25)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Hook.run (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/hooks.js:11:27)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.map.hook (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:344:44)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.method (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:344:20)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runRequest (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:807:12)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at tx (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:728:24)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.try (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:191:50)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at promise.tap.tx (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:191:43)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:191:22)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Object.transaction (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:182:16)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runTransaction (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:903:27)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at uriParser.parseOData.then.then.request (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:711:30)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Holder$2._callFunction (<anonymous>:19:29)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at requestPart (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:711:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.each.p (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/control-flow.js:32:16)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at mapTill (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/control-flow.js:31:20)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runHooks.then (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:693:16)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at exports.handleODataRequest (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:684:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:131:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Route.dispatch (/usr/src/app/node_modules/express/lib/router/route.js:112:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at /usr/src/app/node_modules/express/lib/router/index.js:281:22
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:354:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:365:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:410:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:117:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at app.all (/usr/src/app/src/platform/versions.ts:11:9)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:131:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Route.dispatch (/usr/src/app/node_modules/express/lib/router/route.js:112:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at /usr/src/app/node_modules/express/lib/router/index.js:281:22
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:354:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:365:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:410:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at passport.authenticate (/usr/src/app/src/platform/jwt.ts:104:9)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at JwtStrategy.strategy.success (/usr/src/app/node_modules/passport/lib/middleware/authenticate.js:214:18)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at verified (/usr/src/app/node_modules/passport-jwt/lib/strategy.js:115:41)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runCallback (timers.js:705:18)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at tryOnImmediate (timers.js:676:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at processImmediate (timers.js:658:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at process.topLevelDomainCallback (domain.js:120:23)
Aug 06 15:31:48 7658c5fe8305 api[1469]: { DatabaseError: invalid input syntax for integer: "TEST_ENV"
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at wrapDatabaseError (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:41:15)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at PostgresTx.executeSql (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:143:19)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at abstract_sql_1.getAndCheckBindValues.then.values (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:926:19)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runQuery (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:922:68)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at doRunQuery (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:647:40)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at permissions.addPermissions.then (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:649:24)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Holder$2._callFunction (<anonymous>:19:29)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at uriParser.parseOData.then.request (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:643:57)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Object.exports.getAffectedIds.Promise.method (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:630:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Object.exports.getCurrentRequestAffectedIds.args [as getCurrentRequestAffectedIds] (/usr/src/app/src/platform/index.ts:90:62)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at addEnvHooks (/usr/src/app/src/hooks/resources/envvars.ts:118:23)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Hook.preRunHook [as hookFn] (/usr/src/app/src/hooks/resources/envvars.ts:24:32)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.try (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/hooks.js:12:25)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Hook.run (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/hooks.js:11:27)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.map.hook (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:344:44)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.method (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:344:20)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runRequest (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:807:12)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at tx (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:728:24)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.try (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:191:50)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at promise.tap.tx (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:191:43)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:191:22)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Object.transaction (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:182:16)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runTransaction (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:903:27)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at uriParser.parseOData.then.then.request (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:711:30)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Holder$2._callFunction (<anonymous>:19:29)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at requestPart (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:711:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.each.p (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/control-flow.js:32:16)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at mapTill (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/control-flow.js:31:20)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runHooks.then (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:693:16)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at exports.handleODataRequest (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:684:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:131:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Route.dispatch (/usr/src/app/node_modules/express/lib/router/route.js:112:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at /usr/src/app/node_modules/express/lib/router/index.js:281:22
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:354:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:365:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:410:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:117:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at app.all (/usr/src/app/src/platform/versions.ts:11:9)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:131:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Route.dispatch (/usr/src/app/node_modules/express/lib/router/route.js:112:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at /usr/src/app/node_modules/express/lib/router/index.js:281:22
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:354:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:365:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:410:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at passport.authenticate (/usr/src/app/src/platform/jwt.ts:104:9)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at JwtStrategy.strategy.success (/usr/src/app/node_modules/passport/lib/middleware/authenticate.js:214:18)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at verified (/usr/src/app/node_modules/passport-jwt/lib/strategy.js:115:41)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runCallback (timers.js:705:18)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at tryOnImmediate (timers.js:676:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at processImmediate (timers.js:658:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at process.topLevelDomainCallback (domain.js:120:23)
Aug 06 15:31:48 7658c5fe8305 api[1469]:   message: 'invalid input syntax for integer: "TEST_ENV"',
Aug 06 15:31:48 7658c5fe8305 api[1469]:   name: 'DatabaseError',
Aug 06 15:31:48 7658c5fe8305 api[1469]:   code: '22P02' }
Aug 06 15:31:48 7658c5fe8305 api[1469]: { DatabaseError: invalid input syntax for integer: "TEST_ENV"
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at wrapDatabaseError (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:41:15)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at PostgresTx.executeSql (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:143:19)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at abstract_sql_1.getAndCheckBindValues.then.values (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:926:19)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runQuery (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:922:68)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at doRunQuery (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:647:40)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at permissions.addPermissions.then (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:649:24)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Holder$2._callFunction (<anonymous>:19:29)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at uriParser.parseOData.then.request (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:643:57)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Object.exports.getAffectedIds.Promise.method (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:630:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Object.exports.getCurrentRequestAffectedIds.args [as getCurrentRequestAffectedIds] (/usr/src/app/src/platform/index.ts:90:62)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at addEnvHooks (/usr/src/app/src/hooks/resources/envvars.ts:118:23)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Hook.preRunHook [as hookFn] (/usr/src/app/src/hooks/resources/envvars.ts:24:32)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.try (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/hooks.js:12:25)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Hook.run (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/hooks.js:11:27)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.map.hook (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:344:44)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.method (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:344:20)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runRequest (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:807:12)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at tx (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:728:24)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.try (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:191:50)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at promise.tap.tx (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:191:43)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:191:22)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Object.transaction (/usr/src/app/node_modules/@resin/pinejs/out/database-layer/db.js:182:16)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runTransaction (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:903:27)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at uriParser.parseOData.then.then.request (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:711:30)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Holder$2._callFunction (<anonymous>:19:29)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at requestPart (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:711:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Promise.each.p (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/control-flow.js:32:16)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at mapTill (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/control-flow.js:31:20)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runHooks.then (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:693:16)
Aug 06 15:31:48 7658c5fe8305 api[1469]: From previous event:
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at exports.handleODataRequest (/usr/src/app/node_modules/@resin/pinejs/out/sbvr-api/sbvr-utils.js:684:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:131:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:131:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Route.dispatch (/usr/src/app/node_modules/express/lib/router/route.js:112:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at /usr/src/app/node_modules/express/lib/router/index.js:281:22
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:354:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:365:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:410:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:117:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at app.all (/usr/src/app/src/platform/versions.ts:11:9)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:137:13)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/route.js:131:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Route.dispatch (/usr/src/app/node_modules/express/lib/router/route.js:112:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at /usr/src/app/node_modules/express/lib/router/index.js:281:22
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:354:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at param (/usr/src/app/node_modules/express/lib/router/index.js:365:14)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:410:3)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at passport.authenticate (/usr/src/app/src/platform/jwt.ts:104:9)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at JwtStrategy.strategy.success (/usr/src/app/node_modules/passport/lib/middleware/authenticate.js:214:18)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at verified (/usr/src/app/node_modules/passport-jwt/lib/strategy.js:115:41)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at runCallback (timers.js:705:18)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at tryOnImmediate (timers.js:676:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at processImmediate (timers.js:658:5)
Aug 06 15:31:48 7658c5fe8305 api[1469]:     at process.topLevelDomainCallback (domain.js:120:23)
Aug 06 15:31:48 7658c5fe8305 api[1469]:   message: 'Database error',
Aug 06 15:31:48 7658c5fe8305 api[1469]:   name: 'DatabaseError',
Aug 06 15:31:48 7658c5fe8305 api[1469]:   code: '22P02' }

Oh my, I figured it out:
I should be using the variable id instead of its name, AS STATED IN THE DOCS :man_facepalming:

https://www.balena.io/docs/reference/cli/#env-rm-id

Still, now I don’t get an error but the variable doesn’t seem to go away :thinking:

$ balena envs --device 59525b1
ID NAME     VALUE
6  TEST_ENV 1

$ DEBUG=1 balena env rm 6 --device c250187 -y
Debug: original argv0="C:\Program Files\nodejs\node.exe" argv=[C:\Program Files\nodejs\node.exe,C:\Program Files\nodejs\node_modules\balena-cli\bin\balena,env,rm,6,--device,c250187,-y] length=8

$ balena envs --device 59525b1
ID NAME     VALUE
6  TEST_ENV 1

I think the issue here is that you’re passing along the device id after the --device command. If you remove the device id it works fine:

$(04:57 pm) ~/ balena envs --device f37237e1a23d63ee2f8dda427d8736be
ID     NAME VALUE
137963 TEST 1
$(04:57 pm) ~/ balena env rm 137963 --device f37237e1a23d63ee2f8dda427d8736be -y
$(04:58 pm) ~/ balena envs --device f37237e1a23d63ee2f8dda427d8736be
ID     NAME VALUE
137963 TEST 1
$(04:58 pm) ~/ balena env rm 137963 --device
? Are you sure you want to delete the environment variable? Yes
$(04:58 pm) ~/ balena envs --device f37237e1a23d63ee2f8dda427d8736be
No environment variables found

If you need help, don't hesitate in contacting us at:

  GitHub: https://github.com/balena-io/balena-cli/issues/new
  Forums: https://forums.balena.io

$(04:58 pm) ~/ 

Its unexpected that the command would fail silently, whilst providing a false positive response, when providing the additional argument. I’ve opened a GitHub issue to track this that you can see here https://github.com/balena-io/balena-cli/issues/1380

1 Like

Oh my god that’s it!
The naming is super confusing. --device everywhere across the cli is used to pass a device ID.
I definitely get why this works this way, but maybe it should be changed a bit or better explained for clarity.
Thanks a lot for your time!

I agree with you that this is confusing behaviour - It seems that you’ve experienced several usability issues one after the other! I’ll try and take some time to look into this tomorrow and see if I can improve the situation.

1 Like

Hi,
As of v11.8.1 balena CLI contains a few improvements to the balena env rm command. If a string is passed instead of an integer ID then a warning message will be printed and similarly, if an extra argument is present (i.e. a device ID after the -d flag) a warning message will also be printed.
Thanks for reporting this issue!

1 Like