Skip to content

Commit efc21bc

Browse files
authored
Merge pull request #2587 from RedisInsight/be/bugfix/RI-4931-fix-cli-transaction-response
#RI-4931 convert Error to string for RAW mode to avoid empt object re…
2 parents b505d0f + 197f294 commit efc21bc

File tree

6 files changed

+85
-5
lines changed

6 files changed

+85
-5
lines changed

redisinsight/api/src/common/transformers/redis-reply/strategies/ascii-formatter.strategy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ export class ASCIIFormatterStrategy implements IFormatterStrategy {
3030
return result;
3131
}
3232

33-
private formatRedisObjectReply(reply: Object): object {
33+
private formatRedisObjectReply(reply: Object): object | string {
3434
const result = {};
35+
36+
if (reply instanceof Error) {
37+
return reply.toString();
38+
}
39+
3540
Object.keys(reply).forEach((key) => {
3641
result[key] = this.format(reply[key]);
3742
});

redisinsight/api/src/common/transformers/redis-reply/strategies/utf8-formatter.strategy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ export class UTF8FormatterStrategy implements IFormatterStrategy {
3030
return result;
3131
}
3232

33-
private formatRedisObjectReply(reply: Object): object {
33+
private formatRedisObjectReply(reply: Object): object | string {
3434
const result = {};
35+
36+
if (reply instanceof Error) {
37+
return reply.toString();
38+
}
39+
3540
Object.keys(reply).forEach((key) => {
3641
result[key] = this.format(reply[key]);
3742
});

redisinsight/api/src/modules/cli/controllers/cli.controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
Body,
33
Controller,
44
Delete,
5-
Param,
65
Patch,
76
Post,
87
UsePipes,

redisinsight/api/src/modules/cli/services/cli-business/output-formatter/strategies/raw-formatter.strategy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isArray, isObject } from 'lodash';
22
import { getASCIISafeStringFromBuffer } from 'src/utils/cli-helper';
3+
import { ReplyError } from 'src/models';
34
import { IOutputFormatterStrategy } from '../output-formatter.interface';
45

56
export class RawFormatterStrategy implements IOutputFormatterStrategy {
@@ -30,8 +31,13 @@ export class RawFormatterStrategy implements IOutputFormatterStrategy {
3031
return result;
3132
}
3233

33-
private formatRedisObjectReply(reply: Object): object {
34+
private formatRedisObjectReply(reply: Object): object | string {
3435
const result = {};
36+
37+
if (reply instanceof Error) {
38+
return reply.toString();
39+
}
40+
3541
Object.keys(reply).forEach((key) => {
3642
result[key] = this.format(reply[key]);
3743
});

redisinsight/api/src/modules/cli/services/cli-business/output-formatter/strategies/utf-8-formatter.strategy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ export class UTF8FormatterStrategy implements IOutputFormatterStrategy {
3030
return result;
3131
}
3232

33-
private formatRedisObjectReply(reply: Object): object {
33+
private formatRedisObjectReply(reply: Object): object | string {
3434
const result = {};
35+
36+
if (reply instanceof Error) {
37+
return reply.toString();
38+
}
39+
3540
Object.keys(reply).forEach((key) => {
3641
result[key] = this.format(reply[key]);
3742
});

redisinsight/api/test/api/cli/POST-databases-id-cli-uuid-send_command.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,3 +1039,63 @@ describe('POST /databases/:instanceId/cli/:uuid/send-command', () => {
10391039
].map(mainCheckFn);
10401040
})
10411041
});
1042+
1043+
describe('POST /databases/:instanceId/cli/:uuid/send-command (MULTI)', () => {
1044+
requirements('rte.type=STANDALONE');
1045+
1046+
before(rte.data.truncate);
1047+
// Create Redis client for CLI
1048+
before(async () => await request(server).patch(`/${constants.API.DATABASES}/${constants.TEST_INSTANCE_ID}/cli/${constants.TEST_CLI_UUID_1}`))
1049+
1050+
describe('Raw output', () => {
1051+
[
1052+
{
1053+
name: 'Should start transaction',
1054+
data: {
1055+
command: `multi`,
1056+
outputFormat: 'RAW',
1057+
},
1058+
responseRawSchema,
1059+
checkFn: ({ body }) => {
1060+
expect(body.response).to.eq("OK");
1061+
},
1062+
},
1063+
{
1064+
name: 'Should create string',
1065+
data: {
1066+
command: `set ${constants.TEST_STRING_KEY_1} bar`,
1067+
outputFormat: 'RAW',
1068+
},
1069+
responseRawSchema,
1070+
checkFn: ({ body }) => {
1071+
expect(body.response).to.eq("QUEUED")
1072+
},
1073+
},
1074+
{
1075+
name: 'Should create string',
1076+
data: {
1077+
command: `incr ${constants.TEST_STRING_KEY_1}`,
1078+
outputFormat: 'RAW',
1079+
},
1080+
responseRawSchema,
1081+
checkFn: ({ body }) => {
1082+
expect(body.response).to.eq("QUEUED")
1083+
},
1084+
},
1085+
{
1086+
name: 'Should create string',
1087+
data: {
1088+
command: 'exec',
1089+
outputFormat: 'RAW',
1090+
},
1091+
responseRawSchema,
1092+
checkFn: ({ body }) => {
1093+
expect(body.response).to.deep.eq([
1094+
'OK',
1095+
'ReplyError: ERR value is not an integer or out of range',
1096+
]);
1097+
},
1098+
},
1099+
].map(mainCheckFn);
1100+
})
1101+
});

0 commit comments

Comments
 (0)