-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #894 from chromaui/improve-upload-logging
Improve logging around upload errors
- Loading branch information
Showing
7 changed files
with
66 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { uploadFailed } from './uploadFailed'; | ||
|
||
export default { | ||
title: 'CLI/Messages/Errors', | ||
}; | ||
|
||
const target = { | ||
contentLength: 12345, | ||
localPath: 'local/path/to/file.js', | ||
targetPath: 'file.js', | ||
contentType: 'text/javascript', | ||
fileKey: 'file-key', | ||
filePath: 'file.js', | ||
formAction: 'https://bucket.s3.amazonaws.com/', | ||
formFields: { key: 'file-key', 'Content-Type': 'text/javascript' }, | ||
}; | ||
|
||
export const UploadFailed = () => uploadFailed({ target }); | ||
|
||
export const UploadFailedDebug = () => uploadFailed({ target }, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import chalk from 'chalk'; | ||
import { dedent } from 'ts-dedent'; | ||
|
||
import { error as icon } from '../../components/icons'; | ||
import { FileDesc, TargetInfo } from '../../../types'; | ||
|
||
const encode = (path: string) => path.split('/').map(encodeURIComponent).join('/'); | ||
|
||
export function uploadFailed({ target }: { target: FileDesc & TargetInfo }, debug = false) { | ||
const diagnosis = | ||
encode(target.targetPath) !== target.targetPath | ||
? 'It seems the file path may contain illegal characters.' | ||
: 'The file may have been modified during the upload process.'; | ||
const message = dedent(chalk` | ||
${icon} Failed to upload {bold ${target.localPath}} to {bold ${target.targetPath}} | ||
${diagnosis} | ||
${debug ? '' : chalk`Enable the {bold debug} option to get more information.`} | ||
`); | ||
return debug ? message + JSON.stringify(target, null, 2) : message; | ||
} |