Fix attachment streaming errors and add observability for failed attachments#136
Fix attachment streaming errors and add observability for failed attachments#136gasperzgonec wants to merge 16 commits intomainfrom
Conversation
Before, some error messages contained [object Object], so I had to add JSON.stringify(<error>) to fix that. I changed `. "+error` to `.", error`, which automatically adds a space and stringifies the error.
| return { | ||
| error: { | ||
| message: | ||
| `Error while streaming to artifact for attachment ID ${attachment.id}. Skipping attachment. ` + | ||
| JSON.stringify(serializeError(uploadedArtifactError)), | ||
| fileSize: fileSize, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Let's think of solving this in serializeError or somewhere else (maybe even in emit - if string passed just forward, if not stringify and forward). Correct me if I am wrong but you stringified here (and on few other places) because ErrorRecord interface requires message to be a string.
There was a problem hiding this comment.
I changed how the serializeError works; it now returns strings no matter what. If it's JSON error, it stringifies it, so that we can remove the JSON.stringify calls everywhere.
There was a problem hiding this comment.
Can you check this? I remember we had issues in past when stringifying errors. Were getting empty objects as output sometimes and it was hard to debug.
| ); | ||
| if (fileError) { | ||
| return { | ||
| error: new Error( |
There was a problem hiding this comment.
Can you check if we need to wrap this in Error?
There was a problem hiding this comment.
This has to be an error, as we're returning Promise<UploadResponse>, which contains a field error, which is optional, but is of type ErrorRecord:
/**
* UploadResponse is an interface that defines the structure of the response from upload through Uploader.
*/
export interface UploadResponse {
artifact?: Artifact;
error?: ErrorRecord;
}
/**
* ErrorRecord is an interface that defines the structure of an error record.
*/
export interface ErrorRecord {
message: string;
}There was a problem hiding this comment.
Yes but ErrorRecord is type defined by us, while Error is generic error constructor in JavaScript (which coincidentally has message field).
| ): Promise<UploaderResult<ArtifactToUpload>> { | ||
| const url = `${this.devrevApiEndpoint}/internal/airdrop.artifacts.upload-url`; | ||
|
|
||
| if (fileSize != null && fileSize! <= 0) { |
There was a problem hiding this comment.
So you actually made fileSize required parameter? I am not sure if we should do that because s3interact accepts size not to be specified in first this request if I remember correctly, but please check.
I would rather do sth like if(fileSize && fileSize >= 0) { return error }.
There was a problem hiding this comment.
fileSize is not required. What this check is doing, is that if the fileSize is provided and it's either 0 or negative, we throw an error, as the fileSize cannot be negative and a size of 0 isn't allowed.
There was a problem hiding this comment.
Okay so we can check it with this only then: if(fileSize! <= 0) {return error}.
| error: { | ||
| message: `Error while preparing artifact for attachment ID ${ | ||
| attachment.id | ||
| }. Skipping attachment. ${JSON.stringify( |
There was a problem hiding this comment.
We stringify in serializeError already so we don't need to stringify here, right?
| return { | ||
| error: { | ||
| message: | ||
| `Error while streaming to artifact for attachment ID ${attachment.id}. Skipping attachment. ` + | ||
| JSON.stringify(serializeError(uploadedArtifactError)), | ||
| fileSize: fileSize, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Can you check this? I remember we had issues in past when stringifying errors. Were getting empty objects as output sometimes and it was hard to debug.
|
|
||
| // If response is `undefined`, we have hit the timeout in the adapter. | ||
| if (!response) { | ||
| continue; |
There was a problem hiding this comment.
Why is response undefined if we hit adapter timeout? If there is soft timeout we can still finish this iteretion and next iteration will break from the while loop here.
| ); | ||
| if (fileError) { | ||
| return { | ||
| error: new Error( |
There was a problem hiding this comment.
Yes but ErrorRecord is type defined by us, while Error is generic error constructor in JavaScript (which coincidentally has message field).
| ): Promise<UploaderResult<ArtifactToUpload>> { | ||
| const url = `${this.devrevApiEndpoint}/internal/airdrop.artifacts.upload-url`; | ||
|
|
||
| if (fileSize != null && fileSize! <= 0) { |
There was a problem hiding this comment.
Okay so we can check it with this only then: if(fileSize! <= 0) {return error}.
Co-authored-by: Radovan Jorgić <radovanjorgic14@gmail.com>
Description
This PR fixes the following issues:
Connected Issues
Checklist
npm run testOR no tests needed.npm run test:backwards-compatibility.npm run lint.