mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-11 17:51:33 +00:00
Don’t validate error codes on client side (#3131)
* Don’t validate error codes on client side * Update docs * Format * Format * Format
This commit is contained in:
@ -1109,7 +1109,8 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
"code": 468,
|
||||
"errors": [
|
||||
"example error message"
|
||||
]
|
||||
],
|
||||
"title": "TASK_FAILED"
|
||||
},
|
||||
"task_id": "00000000-0000-0000-0000-000000000000",
|
||||
"task_type": "libfuzzer_fuzz"
|
||||
@ -1130,7 +1131,8 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
"Error": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"$ref": "#/definitions/ErrorCode"
|
||||
"title": "Code",
|
||||
"type": "integer"
|
||||
},
|
||||
"errors": {
|
||||
"items": {
|
||||
@ -1138,56 +1140,20 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
},
|
||||
"title": "Errors",
|
||||
"type": "array"
|
||||
},
|
||||
"title": {
|
||||
"title": "Title",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"code",
|
||||
"title",
|
||||
"errors"
|
||||
],
|
||||
"title": "Error",
|
||||
"type": "object"
|
||||
},
|
||||
"ErrorCode": {
|
||||
"description": "An enumeration.",
|
||||
"enum": [
|
||||
450,
|
||||
451,
|
||||
452,
|
||||
453,
|
||||
454,
|
||||
455,
|
||||
456,
|
||||
457,
|
||||
458,
|
||||
459,
|
||||
460,
|
||||
461,
|
||||
462,
|
||||
463,
|
||||
464,
|
||||
465,
|
||||
467,
|
||||
468,
|
||||
469,
|
||||
470,
|
||||
471,
|
||||
472,
|
||||
473,
|
||||
474,
|
||||
475,
|
||||
476,
|
||||
477,
|
||||
478,
|
||||
479,
|
||||
480,
|
||||
481,
|
||||
482,
|
||||
483,
|
||||
484,
|
||||
485
|
||||
],
|
||||
"title": "ErrorCode"
|
||||
},
|
||||
"JobConfig": {
|
||||
"properties": {
|
||||
"build": {
|
||||
@ -1762,7 +1728,8 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
"code": 472,
|
||||
"errors": [
|
||||
"example error message"
|
||||
]
|
||||
],
|
||||
"title": "PROXY_FAILED"
|
||||
},
|
||||
"proxy_id": "00000000-0000-0000-0000-000000000000",
|
||||
"region": "eastus"
|
||||
@ -1777,7 +1744,8 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
"Error": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"$ref": "#/definitions/ErrorCode"
|
||||
"title": "Code",
|
||||
"type": "integer"
|
||||
},
|
||||
"errors": {
|
||||
"items": {
|
||||
@ -1785,55 +1753,19 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
},
|
||||
"title": "Errors",
|
||||
"type": "array"
|
||||
},
|
||||
"title": {
|
||||
"title": "Title",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"code",
|
||||
"title",
|
||||
"errors"
|
||||
],
|
||||
"title": "Error",
|
||||
"type": "object"
|
||||
},
|
||||
"ErrorCode": {
|
||||
"description": "An enumeration.",
|
||||
"enum": [
|
||||
450,
|
||||
451,
|
||||
452,
|
||||
453,
|
||||
454,
|
||||
455,
|
||||
456,
|
||||
457,
|
||||
458,
|
||||
459,
|
||||
460,
|
||||
461,
|
||||
462,
|
||||
463,
|
||||
464,
|
||||
465,
|
||||
467,
|
||||
468,
|
||||
469,
|
||||
470,
|
||||
471,
|
||||
472,
|
||||
473,
|
||||
474,
|
||||
475,
|
||||
476,
|
||||
477,
|
||||
478,
|
||||
479,
|
||||
480,
|
||||
481,
|
||||
482,
|
||||
483,
|
||||
484,
|
||||
485
|
||||
],
|
||||
"title": "ErrorCode"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
@ -2708,7 +2640,8 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
"code": 456,
|
||||
"errors": [
|
||||
"example error message"
|
||||
]
|
||||
],
|
||||
"title": "UNABLE_TO_RESIZE"
|
||||
},
|
||||
"pool_name": "example",
|
||||
"scaleset_id": "example-000"
|
||||
@ -2723,7 +2656,8 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
"Error": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"$ref": "#/definitions/ErrorCode"
|
||||
"title": "Code",
|
||||
"type": "integer"
|
||||
},
|
||||
"errors": {
|
||||
"items": {
|
||||
@ -2731,55 +2665,19 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
},
|
||||
"title": "Errors",
|
||||
"type": "array"
|
||||
},
|
||||
"title": {
|
||||
"title": "Title",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"code",
|
||||
"title",
|
||||
"errors"
|
||||
],
|
||||
"title": "Error",
|
||||
"type": "object"
|
||||
},
|
||||
"ErrorCode": {
|
||||
"description": "An enumeration.",
|
||||
"enum": [
|
||||
450,
|
||||
451,
|
||||
452,
|
||||
453,
|
||||
454,
|
||||
455,
|
||||
456,
|
||||
457,
|
||||
458,
|
||||
459,
|
||||
460,
|
||||
461,
|
||||
462,
|
||||
463,
|
||||
464,
|
||||
465,
|
||||
467,
|
||||
468,
|
||||
469,
|
||||
470,
|
||||
471,
|
||||
472,
|
||||
473,
|
||||
474,
|
||||
475,
|
||||
476,
|
||||
477,
|
||||
478,
|
||||
479,
|
||||
480,
|
||||
481,
|
||||
482,
|
||||
483,
|
||||
484,
|
||||
485
|
||||
],
|
||||
"title": "ErrorCode"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
@ -3411,7 +3309,8 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
"code": 468,
|
||||
"errors": [
|
||||
"example error message"
|
||||
]
|
||||
],
|
||||
"title": "TASK_FAILED"
|
||||
},
|
||||
"job_id": "00000000-0000-0000-0000-000000000000",
|
||||
"task_id": "00000000-0000-0000-0000-000000000000",
|
||||
@ -3451,7 +3350,8 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
"Error": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"$ref": "#/definitions/ErrorCode"
|
||||
"title": "Code",
|
||||
"type": "integer"
|
||||
},
|
||||
"errors": {
|
||||
"items": {
|
||||
@ -3459,56 +3359,20 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
},
|
||||
"title": "Errors",
|
||||
"type": "array"
|
||||
},
|
||||
"title": {
|
||||
"title": "Title",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"code",
|
||||
"title",
|
||||
"errors"
|
||||
],
|
||||
"title": "Error",
|
||||
"type": "object"
|
||||
},
|
||||
"ErrorCode": {
|
||||
"description": "An enumeration.",
|
||||
"enum": [
|
||||
450,
|
||||
451,
|
||||
452,
|
||||
453,
|
||||
454,
|
||||
455,
|
||||
456,
|
||||
457,
|
||||
458,
|
||||
459,
|
||||
460,
|
||||
461,
|
||||
462,
|
||||
463,
|
||||
464,
|
||||
465,
|
||||
467,
|
||||
468,
|
||||
469,
|
||||
470,
|
||||
471,
|
||||
472,
|
||||
473,
|
||||
474,
|
||||
475,
|
||||
476,
|
||||
477,
|
||||
478,
|
||||
479,
|
||||
480,
|
||||
481,
|
||||
482,
|
||||
483,
|
||||
484,
|
||||
485
|
||||
],
|
||||
"title": "ErrorCode"
|
||||
},
|
||||
"StatsFormat": {
|
||||
"description": "An enumeration.",
|
||||
"enum": [
|
||||
@ -5530,7 +5394,8 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
"Error": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"$ref": "#/definitions/ErrorCode"
|
||||
"title": "Code",
|
||||
"type": "integer"
|
||||
},
|
||||
"errors": {
|
||||
"items": {
|
||||
@ -5538,56 +5403,20 @@ If webhook is set to have Event Grid message format then the payload will look a
|
||||
},
|
||||
"title": "Errors",
|
||||
"type": "array"
|
||||
},
|
||||
"title": {
|
||||
"title": "Title",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"code",
|
||||
"title",
|
||||
"errors"
|
||||
],
|
||||
"title": "Error",
|
||||
"type": "object"
|
||||
},
|
||||
"ErrorCode": {
|
||||
"description": "An enumeration.",
|
||||
"enum": [
|
||||
450,
|
||||
451,
|
||||
452,
|
||||
453,
|
||||
454,
|
||||
455,
|
||||
456,
|
||||
457,
|
||||
458,
|
||||
459,
|
||||
460,
|
||||
461,
|
||||
462,
|
||||
463,
|
||||
464,
|
||||
465,
|
||||
467,
|
||||
468,
|
||||
469,
|
||||
470,
|
||||
471,
|
||||
472,
|
||||
473,
|
||||
474,
|
||||
475,
|
||||
476,
|
||||
477,
|
||||
478,
|
||||
479,
|
||||
480,
|
||||
481,
|
||||
482,
|
||||
483,
|
||||
484,
|
||||
485
|
||||
],
|
||||
"title": "ErrorCode"
|
||||
},
|
||||
"EventCrashReported": {
|
||||
"properties": {
|
||||
"container": {
|
||||
|
@ -168,11 +168,17 @@ public record Proxy
|
||||
) : StatefulEntityBase<VmState>(State);
|
||||
|
||||
public record Error(ErrorCode Code, List<string>? Errors) {
|
||||
public static Error Create(ErrorCode code, params string[] errors) {
|
||||
return new Error(code, errors.ToList());
|
||||
}
|
||||
// A human-readable version of the ErrorCode,
|
||||
// so that when serialized to JSON there is something useful,
|
||||
// not just a number. This is named 'Title' to align with the
|
||||
// ProblemDetails class.
|
||||
public string Title => Code.ToString();
|
||||
|
||||
public static Error Create(ErrorCode code, params string[] errors)
|
||||
=> new(code, errors.ToList());
|
||||
|
||||
public sealed override string ToString() {
|
||||
var errorsString = Errors != null ? string.Join("", Errors) : string.Empty;
|
||||
var errorsString = Errors != null ? string.Concat("; ", Errors) : string.Empty;
|
||||
return $"Error {{ Code = {Code}, Errors = {errorsString} }}";
|
||||
}
|
||||
};
|
||||
|
15
src/ApiService/Tests/ErrorTests.cs
Normal file
15
src/ApiService/Tests/ErrorTests.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Xunit;
|
||||
|
||||
namespace Tests;
|
||||
|
||||
public class ErrorTests {
|
||||
|
||||
[Fact]
|
||||
public void JsonHasErrorTitle() {
|
||||
var error = Error.Create(ErrorCode.INVALID_IMAGE);
|
||||
var json = JsonSerializer.Serialize(error);
|
||||
Assert.Equal(@"{""Code"":463,""Errors"":[],""Title"":""INVALID_IMAGE""}", json);
|
||||
}
|
||||
}
|
@ -7,9 +7,9 @@ namespace Tests;
|
||||
public class EventTests {
|
||||
|
||||
[Fact]
|
||||
static void CheckAllEventClass() {
|
||||
public static void CheckAllEventClass() {
|
||||
// instantiate one event to force the static constructor to run
|
||||
var testEvent = new EventPing(Guid.Empty);
|
||||
|
||||
// if it doesn't throw then this test passes
|
||||
_ = new EventPing(Guid.Empty);
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,11 @@ def main() -> None:
|
||||
EventTaskFailed(
|
||||
job_id=UUID(int=0),
|
||||
task_id=UUID(int=0),
|
||||
error=Error(code=ErrorCode.TASK_FAILED, errors=["example error message"]),
|
||||
error=Error(
|
||||
code=ErrorCode.TASK_FAILED.value,
|
||||
title="TASK_FAILED",
|
||||
errors=["example error message"],
|
||||
),
|
||||
user_info=UserInfo(
|
||||
application_id=UUID(int=0),
|
||||
object_id=UUID(int=0),
|
||||
@ -171,7 +175,11 @@ def main() -> None:
|
||||
EventProxyFailed(
|
||||
region=Region("eastus"),
|
||||
proxy_id=UUID(int=0),
|
||||
error=Error(code=ErrorCode.PROXY_FAILED, errors=["example error message"]),
|
||||
error=Error(
|
||||
code=ErrorCode.PROXY_FAILED.value,
|
||||
title="PROXY_FAILED",
|
||||
errors=["example error message"],
|
||||
),
|
||||
),
|
||||
EventProxyStateUpdated(
|
||||
region=Region("eastus"),
|
||||
@ -197,7 +205,9 @@ def main() -> None:
|
||||
scaleset_id="example-000",
|
||||
pool_name=PoolName("example"),
|
||||
error=Error(
|
||||
code=ErrorCode.UNABLE_TO_RESIZE, errors=["example error message"]
|
||||
code=ErrorCode.UNABLE_TO_RESIZE.value,
|
||||
title="UNABLE_TO_RESIZE",
|
||||
errors=["example error message"],
|
||||
),
|
||||
),
|
||||
EventScalesetDeleted(scaleset_id="example-000", pool_name=PoolName("example")),
|
||||
@ -231,7 +241,9 @@ def main() -> None:
|
||||
task_id=UUID(int=0),
|
||||
task_type=TaskType.libfuzzer_fuzz,
|
||||
error=Error(
|
||||
code=ErrorCode.TASK_FAILED, errors=["example error message"]
|
||||
code=ErrorCode.TASK_FAILED.value,
|
||||
title="TASK_FAILED",
|
||||
errors=["example error message"],
|
||||
),
|
||||
),
|
||||
JobTaskStopped(
|
||||
|
@ -18,7 +18,6 @@ from .enums import (
|
||||
Compare,
|
||||
ContainerPermission,
|
||||
ContainerType,
|
||||
ErrorCode,
|
||||
GithubIssueSearchMatch,
|
||||
GithubIssueState,
|
||||
HeartbeatType,
|
||||
@ -95,7 +94,11 @@ class EnumModel(BaseModel):
|
||||
|
||||
|
||||
class Error(BaseModel):
|
||||
code: ErrorCode
|
||||
# the code here is from ErrorCodes.cs, but we don't
|
||||
# want to validate the error code on the client-side
|
||||
code: int
|
||||
# a human-readable version of the error code
|
||||
title: str
|
||||
errors: List[str]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user