Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jroper committed Mar 9, 2022
1 parent 7eab6ca commit e4da284
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 53 deletions.
4 changes: 3 additions & 1 deletion samples/ts/ts-valueentity-counter/test/testkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export class MockValueEntity<S extends object> {
} else if (ctx.updatedState) {
this.state = ctx.updatedState;
}
this.error = failure;
if (failure !== undefined) {
this.error = failure.description;
}

return grpcMethod.responseDeserialize(
grpcMethod.responseSerialize(message)
Expand Down
56 changes: 23 additions & 33 deletions sdk/integration-test/integration-testkit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ action.commandHandlers = {
ctx.end();
},
Fail: (input, ctx) => {
ctx.fail("some-error", 6);
ctx.fail('some-error', 6);
},
};

Expand All @@ -58,7 +58,7 @@ value_entity.commandHandlers = {
});
},
Fail: (input, state, ctx) => {
ctx.fail("some-error", 6);
ctx.fail('some-error', 6);
},
};

Expand Down Expand Up @@ -90,7 +90,7 @@ entity.setBehavior((e) => {
});
},
Fail: (input, state, ctx) => {
ctx.fail("some-error", 6);
ctx.fail('some-error', 6);
},
},
eventHandlers: {},
Expand Down Expand Up @@ -125,17 +125,14 @@ describe('The AkkaServerless IntegrationTestkit', function () {
});

it('should allow actions to fail with custom code', (done) => {
testkit.clients.ExampleService.Fail(
{ field: 'hello' },
(err, msg) => {
err.should.not.be.undefined;
// Unfortunately, this appears to be the only way the JS library offers to read the error description,
// by reading this unspecified message string.
err.message.should.be.eq('6 ALREADY_EXISTS: some-error');
err.code.should.be.eq(6);
done();
},
);
testkit.clients.ExampleService.Fail({ field: 'hello' }, (err, msg) => {
err.should.not.be.undefined;
// Unfortunately, this appears to be the only way the JS library offers to read the error description,
// by reading this unspecified message string.
err.message.should.be.eq('6 ALREADY_EXISTS: some-error');
err.code.should.be.eq(6);
done();
});
});

it('should handle value entities sync handlers', (done) => {
Expand All @@ -159,15 +156,12 @@ describe('The AkkaServerless IntegrationTestkit', function () {
});

it('should allow value entities to fail with custom code', (done) => {
testkit.clients.ExampleServiceTwo.Fail(
{ field: 'hello' },
(err, msg) => {
err.should.not.be.undefined;
err.message.should.be.eq('6 ALREADY_EXISTS: some-error');
err.code.should.be.eq(6);
done();
},
);
testkit.clients.ExampleServiceTwo.Fail({ field: 'hello' }, (err, msg) => {
err.should.not.be.undefined;
err.message.should.be.eq('6 ALREADY_EXISTS: some-error');
err.code.should.be.eq(6);
done();
});
});

it('should handle event sourced entities sync handlers', (done) => {
Expand All @@ -191,15 +185,11 @@ describe('The AkkaServerless IntegrationTestkit', function () {
});

it('should allow event sourced entities to fail with custom code', (done) => {
testkit.clients.ExampleServiceThree.Fail(
{ field: 'hello' },
(err, msg) => {
err.should.not.be.undefined;
err.message.should.be.eq('6 ALREADY_EXISTS: some-error');
err.code.should.be.eq(6);
done();
},
);
testkit.clients.ExampleServiceThree.Fail({ field: 'hello' }, (err, msg) => {
err.should.not.be.undefined;
err.message.should.be.eq('6 ALREADY_EXISTS: some-error');
err.code.should.be.eq(6);
done();
});
});

});
4 changes: 2 additions & 2 deletions sdk/src/action-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,10 @@ class ActionHandler {
};
if (grpcStatus !== undefined) {
if (grpcStatus === 0) {
throw new Error("gRPC failure status code must not be OK")
throw new Error('gRPC failure status code must not be OK');
}
if (grpcStatus < 0 || grpcStatus > 16) {
throw new Error("Invalid gRPC status code: " + grpcStatus)
throw new Error('Invalid gRPC status code: ' + grpcStatus);
}
failure.grpcStatusCode = grpcStatus;
}
Expand Down
23 changes: 18 additions & 5 deletions sdk/src/command-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ class CommandHelper {

if (!this.service.methods.hasOwnProperty(command.name)) {
ctx.commandDebug("Command '%s' unknown", command.name);
return errorReply('Unknown command named ' + command.name, 12 /* unimplemented */);
return errorReply(
'Unknown command named ' + command.name,
12 /* unimplemented */,
);
} else {
try {
const grpcMethod = this.service.methods[command.name];
Expand Down Expand Up @@ -155,9 +158,9 @@ class CommandHelper {
const failure = {
commandId: ctx.commandId,
description: msg,
}
};
if (status !== undefined) {
failure.grpcStatusCode = status
failure.grpcStatusCode = status;
}
return {
reply: {
Expand All @@ -173,11 +176,21 @@ class CommandHelper {
const userReply = await this.invoke(handler, ctx);

if (ctx.error !== null) {
return this.errorReply(ctx.error.message, ctx.error.grpcStatus, ctx, desc);
return this.errorReply(
ctx.error.message,
ctx.error.grpcStatus,
ctx,
desc,
);
} else if (userReply instanceof Reply) {
if (userReply.failure) {
// handle failure with a separate write to make sure we don't write back events etc
return this.errorReply(userReply.failure.description, userReply.failure.status, ctx, desc);
return this.errorReply(
userReply.failure.description,
userReply.failure.status,
ctx,
desc,
);
} else {
// effects need to go first to end up in reply
// note that we amend the ctx.reply to get events etc passed along from the entities
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/context-failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export class ContextFailure extends Error {
}
if (grpcStatus !== undefined) {
if (grpcStatus === 0) {
throw new Error("gRPC failure status code must not be OK")
throw new Error('gRPC failure status code must not be OK');
}
if (grpcStatus < 0 || grpcStatus > 16) {
throw new Error("Invalid gRPC status code: " + grpcStatus)
throw new Error('Invalid gRPC status code: ' + grpcStatus);
}
this.grpcStatus = grpcStatus;
}
Expand Down
14 changes: 5 additions & 9 deletions sdk/src/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,13 @@ export function noReply(): Reply {
}

export class Failure {
constructor(
private description: string,
private status?: GrpcStatus
) {
constructor(private description: string, private status?: GrpcStatus) {
if (status !== undefined) {
if (status === GrpcStatus.Ok) {
throw new Error("gRPC failure status code must not be OK")
throw new Error('gRPC failure status code must not be OK');
}
if (status < 0 || status > 16) {
throw new Error("Invalid gRPC status code: " + status)
throw new Error('Invalid gRPC status code: ' + status);
}
}
}
Expand All @@ -268,7 +265,6 @@ export class Failure {
getStatus(): GrpcStatus | undefined {
return this.status;
}

}

/**
Expand All @@ -291,5 +287,5 @@ export enum GrpcStatus {
Internal = 13,
Unavailable = 14,
DataLoss = 15,
Unauthenticated = 16
}
Unauthenticated = 16,
}
4 changes: 3 additions & 1 deletion sdk/test/reply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ describe('Replies', () => {

expect(reply.getFailure()).to.not.be.undefined;
expect(reply.getFailure()?.getDescription()).to.be.eq('my-msg');
expect(reply.getFailure()?.getStatus()).to.be.eq(replies.GrpcStatus.AlreadyExists);
expect(reply.getFailure()?.getStatus()).to.be.eq(
replies.GrpcStatus.AlreadyExists,
);
});

it('should create a forward Reply', () => {
Expand Down

0 comments on commit e4da284

Please sign in to comment.