Skip to content

Commit

Permalink
fix: more error handling in metadata fetching to normalize errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kitop committed Nov 22, 2023
1 parent 7eaed56 commit 2b0337f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/build/src/plugins_core/blobs_upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const coreStep = async function ({
} catch (err) {
logError(logs, `Error uploading blobs to deploy store: ${err.message}`)

const error = new Error(`Failed while uploading blobs to deploy store.`)
const error = new Error(`Failed while uploading blobs to deploy store`)
addErrorInfo(error, { type: 'blobsUploadError' })
throw error
}
Expand Down
9 changes: 7 additions & 2 deletions packages/build/src/plugins_core/blobs_upload/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ async function readMetadata(metadataPath: string): Promise<Record<string, string
}
throw err
}

const metadata = JSON.parse(metadataFile)
let metadata = {}
try {
metadata = JSON.parse(metadataFile)
} catch (err) {
// Normalize the error message
throw new Error(`Error parsing metadata file '${metadataPath}'`)
}
return metadata
}
2 changes: 1 addition & 1 deletion packages/build/tests/blobs_upload/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Generated by [AVA](https://avajs.dev).
Uploading 1 blobs to deploy store...␊
- Uploading blob with-metadata.txt␊
Error uploading blobs to deploy store: Failed while reading 'with-metadata.txt' and its metadata: Unexpected token T in JSON at position 0
Error uploading blobs to deploy store: Failed while reading 'with-metadata.txt' and its metadata: Error parsing metadata file 'packages/build/tests/blobs_upload/fixtures/src_with_malformed_blobs_metadata/dist/.netlify/blobs/deploy/$with-metadata.txt.json'
Core internal error ␊
────────────────────────────────────────────────────────────────␊
Expand Down
Binary file modified packages/build/tests/blobs_upload/snapshots/tests.js.snap
Binary file not shown.

0 comments on commit 2b0337f

Please sign in to comment.