-
Notifications
You must be signed in to change notification settings - Fork 28
Enable Nullable Reference Types #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
core/net6.0/proxy/Apache.OpenWhisk.Runtime.Common/HttpResponseExtension.cs
Show resolved
Hide resolved
| public static async Task WriteError(this HttpResponse response, string errorMessage) | ||
| { | ||
| JObject message = new JObject {{"error", new JValue(errorMessage)}}; | ||
| JObject message = new() {{"error", new JValue(errorMessage)}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorter syntax for constructors. Type is already in the declaration of the variable so, no need to be redundant.
| public class Init | ||
| { | ||
| private readonly SemaphoreSlim _initSemaphoreSlim = new SemaphoreSlim(1, 1); | ||
| private readonly SemaphoreSlim _initSemaphoreSlim = new(initialCount: 1, maxCount: 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorter syntax and clearer parameters.
| string body = await reader.ReadToEndAsync(); | ||
| JObject inputObject = JObject.Parse(body); | ||
| if (!inputObject.ContainsKey("value")) | ||
| if (!inputObject.TryGetValue("value", out JToken? message) || message is not JObject valueObj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use pattern matching to assign valueObj right away.
| { | ||
| await httpContext.Response.WriteError("Missing main/no code to execute."); | ||
| return (null); | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why all return values are between parentheses. Is this enforced by the Scalariform plugin?
| bool binary = valueObj.TryGetValue("binary", out JToken? binaryToken) && binaryToken.ToObject<bool>(); | ||
|
|
||
| if (message["main"] == null || message["binary"] == null || message["code"] == null) | ||
| if (string.IsNullOrWhiteSpace(main) || string.IsNullOrWhiteSpace(code)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are checking only for white space because main and code are guaranteed to not be null.
| archive.ExtractToDirectory(tempPath); | ||
| } | ||
| } | ||
| using MemoryStream stream = new(Convert.FromBase64String(code)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to nest usings anymore.
| try | ||
| { | ||
| string body = await new StreamReader(httpContext.Request.Body).ReadToEndAsync(); | ||
| using StreamReader reader = new(httpContext.Request.Body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be good citizens and dispose any unmanaged resources created by the StreamReader.
| } | ||
|
|
||
| object owObject = _constructor.Invoke(new object[] { }); | ||
| object owObject = _constructor.Invoke(Array.Empty<object>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to allocate an object to invoke the constructor.
|
I forgot to mention that I still cannot run the tests locally in my machine since I can only run openwhisk in standalone mode in a docker container and I don't know how to run the tests against it. I tested manually by running the container for this runtime and sending the base64 encoded tests to it in the expected JSON text. It seems to work fine that way. I found some issues while trying to test it in integration with openwhisk in standalone mode. Specially the array input and output cases. |
I mentioned that this could be a good improvement on the code for this runtime in #91
I probably got carried away with some other changes not specific to enabling NRTs. I will explain my rationale for these and ask questions about other minor details in the code.